ruby zsh:找不到命令:包(在 gem 安装包之后)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28072128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:41:01  来源:igfitidea点击:

zsh: command not found: bundle (after gem install bundle)

rubygembundleropenbsd

提问by Mark Boulder

Why zsh: command not found: bundleafter gem install bundler?

为什么zsh: command not found: bundle之后gem install bundler

I tried setting path=( /usr/local/lib/ruby/gems/2.2/gems/ ~/bin /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin )in /etc/zshrcand source /etc/zshrcto no avail.

我试着设置path=( /usr/local/lib/ruby/gems/2.2/gems/ ~/bin /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin )/etc/zshrcsource /etc/zshrc没有用。

root@dev:/home/dev# gem install bundler
Successfully installed bundler-1.7.12
Parsing documentation for bundler-1.7.12
Done installing documentation for bundler after 10 seconds
1 gem installed

root@dev:/home/dev# bundle
zsh: command not found: bundle

root@dev:/home/dev# uname -a
OpenBSD dev.my.domain 5.7 GENERIC#748 amd64

root@dev:/home/dev# gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.5
  - RUBY VERSION: 2.2.0 (2014-12-25 patchlevel 0) [x86_64-openbsd]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.2
  - RUBY EXECUTABLE: /usr/local/bin/ruby22
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /root/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-openbsd
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/2.2
     - /usr/local/lib/ruby/gems/2.2/gems/
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/lib/ruby/gems/2.2/gems/
     - /root/bin
     - /bin
     - /sbin
     - /usr/bin
     - /usr/sbin
     - /usr/local/bin
     - /usr/local/sbin

回答by Ricardo Rojas

I had the same issue using zsh and this fixed it:

我在使用 zsh 时遇到了同样的问题,并修复了它:

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
$ echo 'eval "$(rbenv init -)"' >> ~/.zshenv
$ echo 'source $HOME/.zshenv' >> ~/.zshrc
$ exec $SHELL

回答by rr-

You seem to be after installing bundlersystem-wide. To do this, you need to pass --no-user-installflag to gemand execute it with sudo:

您似乎是在bundler系统范围内安装之后。为此,您需要将--no-user-install标志传递给gem并使用以下命令执行它sudo

sudo gem install bundler --no-user-install

After this, you should see bundlein /usr/bin/just fine:

在这之后,你应该看到bundle/usr/bin/就好了:

$ ls /usr/bin/bundle
/usr/bin/bundle*

回答by mhutter

You can check the directory in which Rubygems will install gem executables with gem environment.

您可以检查 Rubygems 将在其中安装 gem 可执行文件的目录gem environment

One of the first points should be EXECUTABLE DIRECTORY. Make sure this directory is in your $PATH(listed as SHELL PATHbtw)

第一点之一应该是EXECUTABLE DIRECTORY。确保这个目录在你的$PATH(作为SHELL PATHbtw列出)

回答by Yoyo Coder

You shound run the below command after installed bundler:

安装后你应该运行以下命令bundler

rbenv rehash

回答by Shan Dou

Also just ran into the same error when setting up jekyll. My gem envshows GEM PATHSas follows:

在设置 jekyll 时也遇到了同样的错误。我的gem env显示GEM PATHS如下:

- GEM PATHS:
    - /usr/local/lib/ruby/gems/2.5.0

The content of this directory looks like this:

该目录的内容如下所示:

bin/            cache/          extensions/     specifications/
build_info/     doc/            gems/

Inside bin, I see both jekylland bundle:

在里面bin,我看到了jekyllbundle

$cd /usr/local/lib/ruby/gems/2.5.0/bin/
$ls
bundle        jekyll        listen        safe_yaml     sass-convert
bundler       kramdown      rougify       sass          scss


If you find similar paths and files as I do, any one of the following approaches should work:

如果您发现与我类似的路径和文件,则以下任何一种方法都应该有效:

  • Append the full path /usr/local/lib/ruby/gems/2.5.0/bin/to PATHvia:

    export PATH="/usr/local/lib/ruby/gems/2.5.0/bin/:$PATH"
    
  • Make symbolic links in /usr/local/binvia:

    $cd /usr/local/bin
    $ln -sf /usr/local/lib/ruby/gems/2.5.0/bin/bundle .
    $ln -sf /usr/local/lib/ruby/gems/2.5.0/bin/jekyll .
    
  • Set up aliases in .zshrc(or .bashrcand alike):

    alias jekyll="/usr/local/lib/ruby/gems/2.5.0/bin/jekyll"
    alias bundle="/usr/local/lib/ruby/gems/2.5.0/bin/bundle"
    
  • 将完整路径附加/usr/local/lib/ruby/gems/2.5.0/bin/PATH通过:

    export PATH="/usr/local/lib/ruby/gems/2.5.0/bin/:$PATH"
    
  • /usr/local/bin通过以下方式建立符号链接:

    $cd /usr/local/bin
    $ln -sf /usr/local/lib/ruby/gems/2.5.0/bin/bundle .
    $ln -sf /usr/local/lib/ruby/gems/2.5.0/bin/jekyll .
    
  • .zshrc(或.bashrc类似)中设置别名:

    alias jekyll="/usr/local/lib/ruby/gems/2.5.0/bin/jekyll"
    alias bundle="/usr/local/lib/ruby/gems/2.5.0/bin/bundle"
    


In general, I felt all this path blindness makes the experience of setting up a jekyll site bumpier than expected:( If others have a set of steps that just work (without such needs for troubleshooting), please comment :)

总的来说,我觉得所有这些路径盲目性使得设置 jekyll 站点的体验比预期的要颠簸:(如果其他人有一套可以正常工作的步骤(不需要此类故障排除),请评论:)