我如何强制 "bundle install" 使用 Ruby 的已安装版本?

How do I force "bundle install" to use the installed version of Ruby?

我刚刚重新安装了 Ruby 2.4.0 ...

myuser@myproject:~$ sudo env "PATH=$PATH" rvm reinstall ruby-2.4.0
ruby-2.4.0 - #removing rubies/ruby-2.4.0..
Searching for binary rubies, this might take some time.
Found remote file https://rubies.travis-ci.org/ubuntu/14.04/x86_64/ruby-2.4.0.tar.bz2
Checking requirements for ubuntu.
Requirements installation successful.
ruby-2.4.0 - #configure
ruby-2.4.0 - #download
ruby-2.4.0 - #validate archive
ruby-2.4.0 - #extract
ruby-2.4.0 - #validate binary
ruby-2.4.0 - #setup
ruby-2.4.0 - #gemset created /usr/local/rvm/gems/ruby-2.4.0@global
ruby-2.4.0 - #importing gemset /usr/local/rvm/gemsets/global.gems...................................
ruby-2.4.0 - #generating global wrappers........
ruby-2.4.0 - #gemset created /usr/local/rvm/gems/ruby-2.4.0
ruby-2.4.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.4.0 - #generating default wrappers........
Making gemset ruby-2.4.0 pristine.................................................................
Making gemset ruby-2.4.0@global pristine.................................................................

然而,尽管我看到 "ruby -v" 返回了正确的版本,但我的 "bundle install" 似乎指向 Ruby 的旧版本 ...

rails@myproject:~$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
rails@myproject:~$ cd myproject
rails@myproject:~/myproject$ bundle install
-su: /usr/local/rvm/gems/ruby-2.4.0/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory

如何强制捆绑包指向 Ruby 的正确版本?

捆绑失败,因为您没有在 2.4.0 rvm gemset 中安装捆绑器。要解决此问题,您应该在当前版本的 ruby:

中执行此操作
gem install bundler
bundle

确保您的 Ruby 版本与 Gemfile 上声明的版本相同。