gpt4 book ai didi

ruby - 了解 $PATH 变量 : Installed gems are not in path

转载 作者:数据小太阳 更新时间:2023-10-29 07:37:32 26 4
gpt4 key购买 nike

早上好!

我正在研究 ruby gem 。到目前为止,gem 还没有被推送到任何服务器——目前都是本地开发。

我想在构建 gem 时对其进行测试(使用 TTD)。我运行了 bundle exe rake buildbundle exe rake install 以在我的本地环境中构建和安装 gem。我现在希望当我在终端的任何地方键入 gem_name 时,应该识别 gem_name。不幸的是它不是;相反,我收到此错误:

    `$ -bash gem_name: command not found`

我唯一能想到的可能是我的路径有问题。

这是我的 $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

下面是命令 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)

谢谢!

最佳答案

你应该像这样在 gemspec 中提到你的可执行文件:

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

因此,在安装 ruby​​gems 时,将其复制到 $PATH 上的 /Users/throw/.rvm/gems/ruby-2.2.1/bin

编辑:您的 gemspec 从 git ls-files 获取文件列表,因此所有文件都应在 gem 构建之前提交以包含在 gem 中。

关于ruby - 了解 $PATH 变量 : Installed gems are not in path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34858901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com