为什么 jekyll/bundler 程序正在安装,但没有出现在 gem 列表中

Why are jekyll/bundler programs installing, but not appearing in gem list

我已经“安装”了 bundler 和 jekyll,没有任何问题 以下痕迹:

$ gem install jekyll bundler   
Successfully installed unicode-display_width-1.8.0
Successfully installed terminal-table-2.0.0
Successfully installed safe_yaml-1.0.5
Successfully installed rouge-3.27.0
Successfully installed forwardable-extended-2.6.0
Successfully installed pathutil-0.16.2
Successfully installed mercenary-0.4.0
Successfully installed liquid-4.0.3
Successfully installed rexml-3.2.5
Successfully installed kramdown-2.3.1
Successfully installed kramdown-parser-gfm-1.1.0
Building native extensions. This could take a while...
Successfully installed ffi-1.15.5
Successfully installed rb-inotify-0.10.1
Successfully installed rb-fsevent-0.11.0
Successfully installed listen-3.7.1
Successfully installed jekyll-watch-2.2.1
Building native extensions. This could take a while...
Successfully installed sassc-2.4.0
Successfully installed jekyll-sass-converter-2.1.0
Successfully installed concurrent-ruby-1.1.9
Successfully installed i18n-1.9.0
Building native extensions. This could take a while...
Successfully installed http_parser.rb-0.8.0
Building native extensions. This could take a while...
Successfully installed eventmachine-1.2.7
Successfully installed em-websocket-0.5.3
Successfully installed colorator-1.1.0
Successfully installed public_suffix-4.0.6
Successfully installed addressable-2.8.0
Successfully installed jekyll-4.2.1
Successfully installed bundler-2.3.6
28 gems installed

但 运行 bundlejekyll 返回了 command not found 错误。好的,没问题,我 运行 gem env 找到 GEM PATH 并将其添加到我的路径中。现在找到 bundlejekyll,但它们都给出以下类型的错误:

$ jekyll
/usr/lib/ruby/3.0.0/rubygems.rb:265:in `find_spec_for_exe': can't find gem jekyll (>= 0.a) with executable jekyll (Gem::GemNotFoundException)
        from /usr/lib/ruby/3.0.0/rubygems.rb:284:in `activate_bin_path'
        from /home/<user>/.local/share/gem/ruby/3.0.0/bin/jekyll:25:in `<main>'
$ bundle
/usr/lib/ruby/3.0.0/rubygems.rb:265:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
        from /usr/lib/ruby/3.0.0/rubygems.rb:284:in `activate_bin_path'
        from /home/<user>/.local/share/gem/ruby/3.0.0/bin/bundle:25:in `<main>'

我在其中编辑了上面的代码片段以删除识别信息。一些事情:

Updating rubygems-update
Successfully installed rubygems-update-3.3.6
ERROR:  While executing gem ... (Errno::ENOENT)
    No such file or directory @ dir_chdir - /usr/lib/ruby/gems/3.0.0/gems/rubygems-update-3.3.6

我已经在这个论坛上解决这个问题几天了,但还没有找到解决方案。任何指针将不胜感激。谢谢!

我的建议是确保您的 GEM_PATH 包含您在 GEM_HOME 变量中设置的路径。我自己,我有那些一直有效的环境变量:

export GEM_BIN=/home/user/Code/bin
export GEM_PATH=/home/user/Code/.gem
export GEM_HOME=/home/user/Code/.gem
export PATH=/home/user/Code/bin:$PATH

这里的一个重要说明是,这对于 single-user 系统来说是一个很好的设置,其中每个 gem 安装都是从用户而不是 root 用户完成的。

您的问题也可能源于一个事实,即您通过 rvm 等工具安装了多个版本的 Ruby,例如您的 gem 命令引用了错误的 Ruby 二进制文件.您可以使用 type bash 命令以某种方式了解什么是哪里。在我的例子中:

[user@localhost ~]# type ruby
ruby is /usr/bin/ruby
[user@localhost ~]# type gem
gem is hashed (/usr/bin/gem)
[user@localhost ~]# type bundler
bundler is /home/user/Code/bin/bundler
[user@localhost ~]# type jekyll
jekyll is /home/user/Code/bin/jekyll
[user@localhost ~]#

为确保这些二进制文件调用正确的 Ruby 二进制文件,试试这个:

[user@localhost ~]# head -n1 /home/user/Code/bin/jekyll
#!/usr/bin/ruby
[user@localhost ~]# head -n1 /usr/bin/gem
#!/usr/bin/ruby
[user@localhost ~]# 

在我的例子中它是有效的,但如果你想使用不同于 /usr/bin/ruby 的 Ruby 二进制文件,它可能不正确。