ruby 错误:未安装 Gem bundler,请先运行 `gem install bundler`

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12326705/
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 05:24:30  来源:igfitidea点击:

ERROR: Gem bundler is not installed, run `gem install bundler` first

rubygem

提问by bigpotato

Hi I've been having a probably trying to install the Ruby gem bundle. I follow the directions gem install bundleafter I receive this message, but it still doesn't work when I type bundle -v. I also type

嗨,我一直在尝试安装 Ruby gem 包。gem install bundle收到此消息后,我按照说明进行操作,但是当我输入bundle -v. 我也打字

which bundleand receive

which bundle并接收

/Users/edmundmai/.rvm/bin/bundle

so it exists!! So why does it not work!! Is there something wrong with the mysterious $PATH that I don't get? (I'm a noob).

所以它存在!!那么为什么它不起作用!!我不明白的神秘 $PATH 有什么问题吗?(我是菜鸟)。

Here's my .bash_profile:

这是我的 .bash_profile:

PATH=$PATH:~/bin
export PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

Here's my .bashrc :

这是我的 .bashrc :

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 

Here's my gem env:

这是我的宝石环境:

RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-darwin11.3.1]
- INSTALLATION DIRECTORY: /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd
- RUBY EXECUTABLE: /Users/edmundmai/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
- EXECUTABLE DIRECTORY: /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/bin
- RUBYGEMS PLATFORMS:
  - ruby
  - x86_64-darwin-11
- GEM PATHS:
   - /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd
   - /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@global
- GEM CONFIGURATION:
   - :update_sources => true
   - :verbose => true
   - :benchmark => false
   - :backtrace => false
   - :bulk_threshold => 1000
   - "install" => "--no-rdoc --no-ri"
   - "update" => "--no-rdoc --no-ri"
- REMOTE SOURCES:
   - http://rubygems.org/

echo $PATH

回声 $PATH

/Users/edmundmai/.rvm/bin:/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/bin:/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/edmundmai/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/edmundmai/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/edmundmai/bin:/Users/edmundmai/bin

/Users/edmundmai/.rvm/bin:/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/bin:/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/edmundmai/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/edmundmai/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/edmundmai/bin:/Users/edmundmai/bin

UPDATE So after trying to go through the RoR tutorial again, I repeated a few of the steps from earlier in the chapter in one of my two terminal windows (let's call them Terminal #1 and Terminal #2). Terminal #2 still doesn't work (the command line isn't on any directory, just the default directory) while Terminal #1 (at my sample_app directory) works. I think rvm get head && rvm reloadmight be the key? But does that mean I have to run that every time I open my terminal? Check out my terminal #1 commands for before and after (I deleted some of the output so that it would be more clear what my input lines were):

更新 因此,在再次尝试阅读 RoR 教程之后,我在我的两个终端窗口之一(让我们称它们为终端 #1 和终端 #2)中重复了本章前面的一些步骤。终端 #2 仍然无法工作(命令行不在任何目录中,只是默认目录)而终端 #1(在我的 sample_app 目录中)工作。我想rvm get head && rvm reload可能是关键?但这是否意味着我每次打开终端时都必须运行它?查看我的终端 #1 之前和之后的命令(我删除了一些输出,以便更清楚我的输入行是什么):

Edmunds-MacBook-Pro:sample_app edmundmai$ bundle -v
ERROR: Gem bundler is not installed, run `gem install bundler` first.
Edmunds-MacBook-Pro:sample_app edmundmai$ gem install
ERROR:  While executing gem ... (Gem::CommandLineError)
Please specify at least one gem name (e.g. gem build GEMNAME)
Edmunds-MacBook-Pro:sample_app edmundmai$ rvm -v


rvm 1.15.8 (master) by Wayne E. Seguin <[email protected]>, Michal Papis     <[email protected]> [https://rvm.io/]

Edmunds-MacBook-Pro:sample_app edmundmai$ rspec spec/
No DRb server is running. Running in local process instead ...
........

Finished in 0.36709 seconds
8 examples, 0 failures

Randomized with seed 59500

Edmunds-MacBook-Pro:sample_app edmundmai$ subl .
Edmunds-MacBook-Pro:sample_app edmundmai$ bundle install --binstubs=./bundler_stubs
Using rake (0.9.2.2) 
...
...
(**list of stuff)
Using uglifier (1.2.3) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Edmunds-MacBook-Pro:sample_app edmundmai$ bundle show bundler
/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/bundler-1.2.0

I'm extremely unclear as to what the $PATH does. If you guys need any more info, feel free to tell me and I'll provide it.

我非常不清楚 $PATH 的作用。如果你们需要更多信息,请随时告诉我,我会提供。

回答by jmdeldin

I think this is the problem: You have bundler installed to a specific gemset, which is why it's only available when you're in your app's directory (I'm assuming there's a .rvmrcfile in there).

我认为这是问题所在:您已将 bundler 安装到特定的gemset,这就是为什么它仅在您位于应用程序目录中时才可用(我假设那里有一个.rvmrc文件)。

You have a few options:

您有几个选择:

  1. Install bundlerto a global gemset. rvm gemset use global && gem install bundler
  2. If you have Homebrew installed, just do brew install rubyand avoid rvm altogether. (There's also rbenv and ry as alternatives to rvm, but I just use 1.9.3 across all my apps, so Homebrew is fine.)
  1. 安装bundler到全局 gemset。rvm gemset use global && gem install bundler
  2. 如果您安装了 Homebrew,请brew install ruby完全避免使用 rvm。(还有 rbenv 和 ry 作为 rvm 的替代品,但我只在所有应用程序中使用 1.9.3,所以 Homebrew 很好。)

For reference, $PATHis a shell environmental variable containing a list of directories that hold executables (e.g., echo, ls, vim, etc.). It's intrinsic to shells.

作为参考,$PATH是包含目录的列表,保持可执行文件(例如,壳环境变量echolsvim等等)。它是贝壳的固有特性。

回答by hammady

Sometimes it is just that you are not sourcing rvm correctly, because you are not in a login shell (using screen?). Type

有时只是您没有正确采购 rvm,因为您不在登录 shell 中(使用屏幕?)。类型

    source ~/.rvm/scripts/rvm

And use any bundle command.

并使用任何 bundle 命令。

回答by jlucasps

Add the following line to ~/.bashrcfile

将以下行添加到~/.bashrc文件

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

then reload the file:

然后重新加载文件:

$ source ~/.bashrc

回答by devudilip

Even i had same problem,

即使我有同样的问题,

In server rvm was not selected as default.So

在服务器 rvm 中没有选择为默认值。所以

rvm use 1.9.3 --default

gem install bundler

solved my problem

解决了我的问题

(Problem occurs only when using rvm)

(只有使用rvm时才会出现问题)

回答by Eric Brooke

If you are using rvm create a separate gemset, which are self-contained bundles of gems.

如果您使用 rvm,请创建一个单独的 gemset,它们是自包含的 gem 包。

rvm use 1.9.3@myApplicationNameHere --create --default
  • myApplicationNameHere = change this to your application name
  • create = creates a gemset
  • default = means use this version of ruby and gemset as default
  • myApplicationNameHere = 将此更改为您的应用程序名称
  • create = 创建一个 gemset
  • default = 表示使用这个版本的 ruby​​ 和 gemset 作为默认值

Here is the link to the rvm site and the relevant section https://rvm.io/gemsets/basics/

这是 rvm 站点和相关部分的链接https://rvm.io/gemsets/basics/