请参阅下面的gem env
打印件。看起来安装目录,用户安装目录和GEM路径都搞砸了。我试图为另一个项目安装ruby版本2.3.0并切换到那个项目。我卸载了ruby版本2.3.0并切换回ruby版本2.3.1。我注意到这些RubyGems环境变量搞砸了一些如何:(到处都看到'2.3.0',我认为这是错误的。
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.1
- RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin15]
- INSTALLATION DIRECTORY: /Users/matthewsmith/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- USER INSTALLATION DIRECTORY: /Users/matthewsmith/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/matthewsmith/.rbenv/versions/2.3.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/matthewsmith/.rbenv/versions/2.3.1/bin
- SPEC CACHE DIRECTORY: /Users/matthewsmith/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/matthewsmith/.rbenv/versions/2.3.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /Users/matthewsmith/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- /Users/matthewsmith/.gem/ruby/2.3.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/matthewsmith/.rbenv/versions/2.3.1/bin
- /Users/matthewsmith/.rbenv/libexec
- /Users/matthewsmith/.rbenv/plugins/ruby-build/bin
- /Users/matthewsmith/.nvm/versions/node/v4.5.0/bin
- /Users/matthewsmith/.rbenv/shims
- /Users/matthewsmith/.rbenv/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
答案 0 :(得分:3)
如果安装了多个版本,则必须将项目相关版本设置为默认版本。
要处理具有不同依赖关系的多个项目,可以使用gemset。 RVM支持gemset。替代品也可用于rbenv。
答案 1 :(得分:0)
没有错。我可以看到您使用的是rbenv
,而您的global ruby version is 2.3.1
如果你在终端上跑:
gem env home
它会返回类似的内容:
/Users/matthewsmith/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
显然上面这行代码告诉你有全局rbenv version 2.3.1
,并且在li/ruby/gems
文件夹中你还安装了ruby version 2.3.0
在此文件夹中.rbenv/versions/
将是您要安装的所有ruby版本,或者它们已经安装。
当我安装不同的ruby版本时,让我们说2.3.0
我会这样做:
rbenv install 2.3.0 # install ruby version 2.3.0 using rbenv
rbenv local 2.3.0 # set ruby 2.3.0 to local project. It writes that version to a .ruby-version in your current directory
ruby -v # check your version to confirm that is 2.3.0 for a local project
gem install bundler
bundle install
安装ruby版本的其他选项包括:SHELL
和GLOBAL
rbenv shell 2.3.0 # Will temporarily change your Ruby version on your current shell. This sets the RBENV_VERSION environment variable in your terminal session.
rbenv global 2.3.1 # This will also change your Ruby version, but only the one you are using whenever no other version is specified, e.g. via a .ruby-version file or RBENV_VERSION variable.
注意! 您不需要sudo来安装宝石。 通常情况下,Ruby版本将由您的安装和编写用户。安装宝石不需要额外的权限。
我希望它有所帮助