Ruby on rails Bundler使用了错误的Ruby版本

Ruby on rails Bundler使用了错误的Ruby版本,ruby-on-rails,ruby,bundler,rbenv,Ruby On Rails,Ruby,Bundler,Rbenv,当我尝试启动Rails服务器时,出现以下错误: $ bundle exec rails s Your Ruby version is 2.3.7, but your Gemfile specified ~> 2.3.8 我不明白为什么会这样,因为我使用自制和rbenv将Ruby设置为2.3.8。2.3.7是系统的ruby版本。我使用的是Mac OS 10.14.4 $ ruby -v ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-d

当我尝试启动Rails服务器时,出现以下错误:

$ bundle exec rails s
Your Ruby version is 2.3.7, but your Gemfile specified ~> 2.3.8
我不明白为什么会这样,因为我使用自制和rbenv将Ruby设置为2.3.8。2.3.7是系统的ruby版本。我使用的是Mac OS 10.14.4

$ ruby -v
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-darwin18]

$ rbenv version
2.3.8 (set by /Users/ceasar/foo/.ruby-version)

$ which -a ruby
/Users/ceasar/.rbenv/shims/ruby
/usr/local/opt/ruby@2.3/bin/ruby
/usr/local/bin/ruby
/usr/bin/ruby

$ which -a bundle
/Users/ceasar/.rbenv/shims/bundle
/usr/local/bin/bundle

$ /usr/bin/xcodebuild -version
Xcode 10.2
Build version 10E125

$ brew list ruby@2.3
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/erb
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/gem
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/irb
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/rake
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/rdoc
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/ri
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/ruby
/usr/local/Cellar/ruby@2.3/2.3.8_1/include/ruby-2.3.0/ (25 files)
/usr/local/Cellar/ruby@2.3/2.3.8_1/lib/libruby.2.3.0.dylib
/usr/local/Cellar/ruby@2.3/2.3.8_1/lib/pkgconfig/ruby-2.3.pc
/usr/local/Cellar/ruby@2.3/2.3.8_1/lib/ruby/ (1211 files)
/usr/local/Cellar/ruby@2.3/2.3.8_1/lib/ (3 other files)
/usr/local/Cellar/ruby@2.3/2.3.8_1/share/emacs/ (7 files)
/usr/local/Cellar/ruby@2.3/2.3.8_1/share/man/ (4 files)
/usr/local/Cellar/ruby@2.3/2.3.8_1/share/ri/ (13487 files

$ bundle env | head -n 40
## Environment

```
Bundler       2.0.1
  Platforms   ruby, x86_64-darwin-18
Ruby          2.3.8p459 (2018-10-18 revision 65136) [x86_64-darwin18]
  Full Path   /Users/ceasar/.rbenv/versions/2.3.8/bin/ruby
  Config Dir  /Users/ceasar/.rbenv/versions/2.3.8/etc
RubyGems      2.5.2.3
  Gem Home    /Users/ceasar/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0
  Gem Path    /Users/ceasar/.gem/ruby/2.3.0:/Users/ceasar/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0
  User Path   /Users/ceasar/.gem/ruby/2.3.0
  Bin Dir     /Users/ceasar/.rbenv/versions/2.3.8/bin
Tools
  Git         2.19.2
  RVM         not installed
  rbenv       rbenv 1.1.2
  chruby      not installed
```

## Bundler Build Metadata

```
Built At          2019-01-04
Git SHA           d7ad2192f
Released Version  true
```

## Bundler settings

```
build.libv8
  Set for the current user (/Users/ceasar/.bundle/config): "--with-system-v8"
build.mysql2
  Set for the current user (/Users/ceasar/.bundle/config): "--with-mysql-config=/usr/local/Cellar/mysql@5.7/5.7.24/bin/mysql_config"
path
  Set for your local app (/Users/ceasar/Desktop/beacon/.bundle/config): "vendor/bundle"
disable_shared_gems
  Set for your local app (/Users/ceasar/Desktop/beacon/.bundle/config): true
```
我没有看到任何让我认为应该使用2.3.7的东西

我不知道还能尝试什么


Bundler如何决定使用哪个版本的Ruby,我如何配置它以使用rbenv或我的自制Ruby安装?

如何尝试使用“rvm”

rvm安装2.4.2

此命令将安装另一个ruby版本2.4.2

你可以简单地检查你所有的版本

rvm列表

在此之后,运行您希望的版本,如下所示

rvm
rvm使用


希望这对你有帮助

我不建议使用RVM而不是RBEnv。RBEnv是最新的解决方案之一,大多数人都坚持使用它


请尝试运行
gem update--system
以首先更新捆绑程序。

安装Rbenv并在项目目录中运行以下命令以安装2.3.8:

rbenv install 2.3.8
rbenv local 2.3.8
bundle install --path=vendor/cache

摘要:bundler的错误版本导致问题。使用ruby版本管理器安装所需的ruby版本。然后为您的项目安装正确版本的bundler gem

详细信息:在我的例子中,我正在github上运行一个rails示例,该示例需要一个较旧版本的ruby和bundler,并得到了描述的错误

为了管理我的不同ruby版本,我使用并安装了

我按照以下步骤解决macOS Catalina v10.15.7上的问题:

解决步骤 在运行上述步骤之前,错误消息告诉我需要安装哪个版本的ruby和bundler。系统绑定器的版本错误(我在mac上),使用该版本的初始错误消息给了我以下错误。只有在安装了所需的bundler gem(见上文)之后,才解决了正确的ruby版本(见上文)

解析前的错误
%bundle安装
您的Ruby版本是2.6.3,但您的Gemfile指定了2.4.1
%哪个红宝石
/Users/richardlogwood/.rubies/ruby-2.4.1/bin/ruby
%哪一捆
/usr/bin/bundle
注意,此错误消息指示了所需的捆绑程序版本:

找不到您的/Gemfile.lock。(Gem::GemNotFoundException)
要更新到系统上安装的最新版本,请运行“bundle update--bundler”。
要安装缺少的版本,请运行'gem install bundler:1.16.1`

可能是您的shell缓存了旧的
bundle
命令,请尝试运行
hash-r
。不幸的是,我在没有确定实际解决问题的方法的情况下成功解决了问题。我会把这个问题留待以后,如果有人开始获得多数票,我会接受答案。我尝试了@matt建议的方法,效果很好@马特,请补充这一点作为答案——这对我来说很有效,我想投赞成票。
% ruby-install 2.4.1
# open a new shell so chruby will find  2.4.1
% chruby 2.4.1

% which ruby
/Users/richardlogwood/.rubies/ruby-2.4.1/bin/ruby

% gem install bundler:1.16.1
% which bundle
/Users/richardlogwood/.gem/ruby/2.4.1/bin/bundle

% cd (to the rails project directory)

# Note: it's a rails project so there was a binstub 
# for bundler, hence `bin/bundler` in the project directory*

% bin/bundler install
% rake db:{create,migrate}
% bin/rails s