簡體   English   中英

Bundler 使用了錯誤的 Ruby 版本

[英]Bundler using wrong Ruby version

當我嘗試啟動 Rails 服務器時,出現以下錯誤:

$ bundle exec rails s
Your Ruby version is 2.3.7, but your Gemfile specified ~> 2.3.8

我不明白為什么會這樣,因為我使用 Homebrew 和 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 install 2.4.2

此命令將安裝另一個版本的 ruby​​,2.4.2

你可以簡單地檢查你所擁有的版本

rvm list

在此之后,運行您想要的版本,如下所示,

rvm <version>rvm use <version>

希望對你有幫助!

摘要:錯誤版本的bundler會導致問題。 使用 ruby​​ 版本管理器安裝所需的 ruby​​ 版本。 然后為您的項目安裝正確版本的 bundler gem。

詳細信息:在我的情況下,我在 github 上運行一個 Rails 示例,該示例需要舊版本的 ruby​​ 和 bundler 並得到描述的錯誤。

為了管理我不同的 ruby​​ 版本,我使用ruby-install ​​-install 和chruby都安裝了homebrew

我按照以下步驟解決了 macOS Catalina v10.15.7 上的問題:

解決步驟

% 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

在運行上述步驟之前,錯誤消息告訴我需要安裝哪個版本的 ruby​​ 和 bundler。 系統捆綁程序是錯誤的版本(我在 Mac 上),使用該版本的初始錯誤消息給了我以下錯誤。 只有在安裝了所需的 bundler gem(見上文)之后,才能解決正確的 ruby​​ 版本(見上文)。

解決前的錯誤

% bundle install
Your Ruby version is 2.6.3, but your Gemfile specified 2.4.1
% which ruby
/Users/richardlogwood/.rubies/ruby-2.4.1/bin/ruby
% which bundle
/usr/bin/bundle

請注意,此錯誤消息指示了所需的捆綁程序版本:

Could not find 'bundler' (1.16.1) required by your ... /Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.16.1`

您的捆綁版本是如何安裝的? 我會嘗試重新安裝它,現在安裝了你想要的ruby版本。

我不建議使用 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

由於某些我認為我已經清理的問題,我安裝了 rbenv 並在某些時候手動安裝了 Ruby。 但似乎我/usr/local/bin/{bundle,bundler}仍然存在,當我這樣做時很明顯: which bundle顯示它的位置不在 shims 下(屬於 rbenv)所以我只需要刪除這些,例如rm -rf /usr/local/bin/{bundle,bundler}一切都恢復正常了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM