Understanding the $ PATH Variable: Installed Gems Are Not in the Way

Good morning!

I am working on a ruby ​​pearl. So far, the stone has not been transferred to any server - all local development so far.

I would like to test the gem when I build it (using TTD). I ran bundle exe rake buildboth bundle exe rake installto build and install gem in my local environment. Now I expect that when I find gem_nameanywhere in my terminal that it gem_nameneeds to be recognized. Unfortunately, this is not the case; instead, I get this error:

    `$ -bash gem_name: command not found`

The only thing I can do is lead to some problem with my path.

Here is the result of my $ PATH:

    echo $PATH
    /Users/throw/.rvm/gems/ruby-2.2.1/bin:
    /Users/throw/.rvm/gems/ruby-2.2.1@global/bin:
    /Users/throw/.rvm/rubies/ruby-2.2.1/bin:
    /usr/local:/usr/local/bin:
   /usr/local/sbin:/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:
   /usr/local/git/bin:/Users/throw/.rvm/bin:/Users/throw/.nvm/nvm.sh:
  /Users/throw/.node/bin:/Applications/Postgres.app/Contents/9.5.0.0/latest/bin

And here is the output of the command gem env:

    gem env
    RubyGems Environment:
      - RUBYGEMS VERSION: 2.5.1
      - RUBY VERSION: 2.2.1 (2015-02-26 patchlevel 85) [x86_64-darwin14]
      - INSTALLATION DIRECTORY: /Users/throw/.rvm/gems/ruby-2.2.1
      - USER INSTALLATION DIRECTORY: /Users/throw/.gem/ruby/2.2.0
      - RUBY EXECUTABLE: /Users/throw/.rvm/rubies/ruby-2.2.1/bin/ruby
      - EXECUTABLE DIRECTORY: /Users/throw/.rvm/gems/ruby-2.2.1/bin
      - SPEC CACHE DIRECTORY: /Users/throw/.gem/specs
      - SYSTEM CONFIGURATION DIRECTORY: /Users/throw/.rvm/rubies/ruby-2.2.1/etc
      - RUBYGEMS PLATFORMS:
        - ruby
        - x86_64-darwin-14
      - GEM PATHS:
         - /Users/throw/.rvm/gems/ruby-2.2.1
         - /Users/throw/.rvm/gems/ruby-2.2.1@global
      - GEM CONFIGURATION:
         - :update_sources => true
         - :verbose => true
         - :backtrace => false
         - :bulk_threshold => 1000
      - REMOTE SOURCES:
         - https://rubygems.org/
      - SHELL PATH:
         - /Users/throw/.rvm/gems/ruby-2.2.1/bin
         - /Users/throw/.rvm/gems/ruby-2.2.1@global/bin
         - /Users/throw/.rvm/rubies/ruby-2.2.1/bin
         - /usr/local
         - /usr/local/bin
         - /usr/local/sbin
         - /usr/bin
         - /usr/local/bin
         - /usr/bin
         - /bin
         - /usr/sbin
         - /sbin
         - /usr/local/git/bin
         - /Users/throw/.rvm/bin
         - /Users/throw/.nvm/nvm.sh
         - /Users/throw/.node/bin
         - /Applications/Postgres.app/Contents/9.5.0.0/latest/bin

, gem_name $PATH, ... - ?

gem_name.gemspec:

    # coding: utf-8
    lib = File.expand_path('../lib', __FILE__)
    $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
    require 'instructortools/version'

    Gem::Specification.new do |spec|
      spec.name          = "instructortools"
      spec.version       = Instructortools::VERSION
      spec.authors       = ["Throw"]
      spec.email         = ["throw@gmail.com"]

      spec.summary       = %q{The command line interface instructor tools}
      spec.homepage      = "https://github.com/throw/instructortools-gem"
      spec.license       = "MIT"

      # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
      # delete this section to allow pushing this gem to any host.
      if spec.respond_to?(:metadata)
        spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
      else
        raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
      end

      spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
      spec.bindir        = "exe"
      spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
      spec.require_paths = ["lib"]

      spec.add_development_dependency "bundler", "~> 1.11"
      spec.add_development_dependency "rake", "~> 10.0"
      spec.add_development_dependency "rspec", "~> 3.0"
      spec.add_development_dependency "pry"

      spec.add_runtime_dependency "thor"
    end

exe, :

    #!/usr/bin/env ruby

    require "instructortools"

    Instructortools::CLI.start(ARGV)

!

+4
1

gemspec:

spec.bindir "exe"
spec.executables ["your_script_name"]

, rubygems /Users/throw/.rvm/gems/ruby-2.2.1/bin, $PATH

EDIT: gemspec git ls-files, , gem gem.

+1

Source: https://habr.com/ru/post/1624818/


All Articles