安装了 Ruby 2.4,但当我仍然显示 Ruby 2.3 时



我正在尝试在我的Mac Sierra机器上安装Ruby 2.4。 我以为我已经成功地做到了...

localhost:myproject nataliab$ rvm use 2.4.0
Warning! PATH is not properly set up, '/Users/nataliab/.rvm/gems/ruby-2.3.0/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-2.3.0'.
ruby-2.4.0 is not installed.
To install do: 'rvm install ruby-2.4.0'
localhost:myproject nataliab$ rvm install ruby-2.4.0
Warning! PATH is not properly set up, '/Users/nataliab/.rvm/gems/ruby-2.3.0/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-2.3.0'.
Warning, new version of rvm available '1.28.0', you are using older version '1.26.11'.
You can disable this warning with:    echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable  auto-update  with:    echo rvm_autoupdate_flag=2 >> ~/.rvmrc
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.12/x86_64/ruby-2.4.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Updating certificates in '/usr/local/etc/openssl/cert.pem'.
Requirements installation successful.
Warning: DYLD_LIBRARY_PATH environment variable is set, this might interact with the compilation and ruby.
Installing Ruby from source to: /Users/nataliab/.rvm/rubies/ruby-2.4.0, this may take a while depending on your cpu(s)...
ruby-2.4.0 - #downloading ruby-2.4.0, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 11.9M  100 11.9M    0     0  2715k      0  0:00:04  0:00:04 --:--:-- 2880k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.4.0 - #extracting ruby-2.4.0 to /Users/nataliab/.rvm/src/ruby-2.4.0....
ruby-2.4.0 - #configuring..................................................................
ruby-2.4.0 - #post-configuration.
ruby-2.4.0 - #compiling.............................................................
ruby-2.4.0 - #installing.......
ruby-2.4.0 - #making binaries executable..
Installed rubygems 2.6.8 is newer than 2.4.8 provided with installed ruby, skipping installation, use --force to force  installation.
ruby-2.4.0 - #gemset created /Users/nataliab/.rvm/gems/ruby-2.4.0@global
ruby-2.4.0 - #importing gemset /Users/nataliab/.rvm/gemsets/global.gems...............................................
ruby-2.4.0 - #generating global wrappers........
ruby-2.4.0 - #gemset created /Users/nataliab/.rvm/gems/ruby-2.4.0
ruby-2.4.0 - #importing gemsetfile /Users/nataliab/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.4.0 - #generating default wrappers........
ruby-2.4.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.4.0 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

然后我看到了正确的红宝石版本...

localhost:myproject nataliab$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]

但是当我打开一个新的终端窗口,导航到我的项目目录时,我不再看到新安装的版本......

localhost:myproject nataliab$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin16]

如何让我的版本坚持下去?

更改默认红宝石

$ rvm default ruby-2.4.0
$ rvm list
#rvm rubies
#   ruby-2.3.0 [ x86_64 ]
#=* ruby-2.4.0 [ x86_64 ]
#   ruby-head [ x86_64 ]
## => - current
## =* - current && default
##  * - default

在项目中

  • 不要在 Gemfile 中添加任何"红宝石"2.4.0"行
  • 如果有.rvmrc文件,请将其删除
  • 创建文件(至少某些 RVM 版本要求同时存在版本和 Gemset 文件)

.红宝石版本

2.4.0

.红宝石宝石 app

触发 rvm 以重新加载它们 cd . ruby --version rvm gemset list

  • 安装 2.4.0 的捆绑程序(如果缺少) rvm 2.4.0@global do gem install bundler

最新更新