安装多个版本时,Ruby只有一个版本有效

Only one version of Ruby works when multiple versions are installed

编辑 1: 另一个人报告 similar issue 使用 asdf。

编辑 2: 另一个报道 similar issue.

编辑 3: 我卸载了 rvm,安装了 rvm,安装了 rubyrails,并尝试了一些活动.

编辑 4: Another person mentioned 是我在 .zshrc(或 .bash_profile/.bashrc)中输入的行造成的: RUBYOPT: "-W:no-deprecated -W:no-experimental"

问题:我有两个项目,一个使用 ruby-2.7.0,另一个使用 ruby-2.6.5

每次我安装两个版本的 ruby 时,只有一个版本可以运行 (2.7.0)。 bundle 以及另一个上的 gem 命令将不再有效,但会给出 Traceback....(RuntimeError).

最近的尝试和控制台输出: 控制台输出流程大致为:

  1. 卸载rvm
  2. 安装rvm
  3. 安装ruby-2.7.0
  4. 安装ruby-2.6.5
  5. 对于 ruby-2.7.0,安装 rails
  6. 对于 ruby-2.6.5,安装 rails
  7. 到目前为止一切正常
  8. export PATH="$PATH:$HOME/.rvm/bin" 附加到 ~/.zshrc
  9. 仍然工作正常
  10. 做了echo "export RUBYOPT='-W:no-deprecated -W:no-experimental'" >> ~/.zshrcsource ~/.zshrc
  11. 再次开始注意到问题
  12. ruby-2.6.5 不起作用; ruby-2.7.0 仍然有效
# UNINSTALL RVM
(base) ➜  ~ rvm -v
rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
(base) ➜  ~ which ruby
/Users/nahua/.rvm/rubies/ruby-2.6.5/bin/ruby
(base) ➜  ~ which rails
/usr/bin/rails
(base) ➜  ~ rbenv
zsh: command not found: rbenv
(base) ➜  ~

(base) ➜  ~ rvm implode
Are you SURE you wish for rvm to implode?
This will recursively remove /Users/nahua/.rvm and other rvm traces?
(anything other than 'yes' will cancel) > yes
Removing rvm-shipped binaries (rvm-prompt, rvm, rvm-sudo rvm-shell and rvm-auto-ruby)
Removing rvm wrappers in /Users/nahua/.rvm/bin
Hai! Removing /Users/nahua/.rvm
/Users/nahua/.rvm has been removed.

Note you may need to manually remove /etc/rvmrc and ~/.rvmrc if they exist still.
Please check all .bashrc .bash_profile .profile and .zshrc for RVM source lines and delete or comment out if this was a Per-User installation.
Also make sure to remove `rvm` group if this was a system installation.
Finally it might help to relogin / restart if you want to have fresh environment (like for installing RVM again).

(base) ➜  ~ gem uninstall rvm
Traceback (most recent call last):
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  ~ which ruby
/usr/bin/ruby
(base) ➜  ~ rvm -v
cat: /Users/nahua/.rvm/VERSION: No such file or directory
__rvm_initialize:source:4: no such file or directory: /Users/nahua/.rvm/scripts/base
cat: /Users/nahua/.rvm/VERSION: No such file or directory
rvm  () by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

# COMMENT OFF ALL RVM LINES IN THE FOLLOWING FILES
(base) ➜  ~ subl .bashrc
(base) ➜  ~ subl .profile
(base) ➜  ~ subl .zshrc
(base) ➜  ~ subl .bash_profile
(base) ➜  ~ subl .zlogin
(base) ➜  ~ subl /etc/profile # nothing there
(base) ➜  ~ sudo vim /etc/profile # nothing there
Password:
(base) ➜  ~ exit

# RESTART TERMINAL
(base) ➜  ~ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
(base) ➜  ~ which ruby
/usr/bin/ruby
(base) ➜  ~ which gem
/usr/bin/gem
(base) ➜  ~ which bundle
/usr/bin/bundle
(base) ➜  ~ clear
(base) ➜  ~ rvm list
zsh: command not found: rvm
(base) ➜  ~ rbenv versions
zsh: command not found: rbenv

# INSTALL RVM
(base) ➜  ~ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Warning: Failed to set locale category LC_NUMERIC to en_DE.
Warning: Failed to set locale category LC_TIME to en_DE.
Warning: Failed to set locale category LC_COLLATE to en_DE.
Warning: Failed to set locale category LC_MONETARY to en_DE.
Warning: Failed to set locale category LC_MESSAGES to en_DE.
gpg: key 105BD0E739499BDB: "Piotr Kuczynski <piotr.kuczynski@gmail.com>" not changed
gpg: key 3804BB82D39DC0E3: "Michal Papis (RVM signing) <mpapis@gmail.com>" not changed
gpg: Total number processed: 2
gpg:              unchanged: 2
(base) ➜  ~ \curl -sSL https://get.rvm.io | bash -s stable --ruby
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc
Warning: Failed to set locale category LC_NUMERIC to en_DE.
Warning: Failed to set locale category LC_TIME to en_DE.
Warning: Failed to set locale category LC_COLLATE to en_DE.
Warning: Failed to set locale category LC_MONETARY to en_DE.
Warning: Failed to set locale category LC_MESSAGES to en_DE.
gpg: Signature made Wed Jul 10 10:31:02 2019 CEST
gpg:                using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: Good signature from "Piotr Kuczynski <piotr.kuczynski@gmail.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/Users/nahua/.rvm/archives/rvm-1.29.9.tgz'
Installing RVM to /Users/nahua/.rvm/
    RVM PATH line found in /Users/nahua/.mkshrc /Users/nahua/.profile /Users/nahua/.bashrc /Users/nahua/.zshrc.
    RVM sourcing line found in /Users/nahua/.profile /Users/nahua/.bash_profile /Users/nahua/.zlogin.
Installation of RVM in /Users/nahua/.rvm/ is almost complete:

  * To start using RVM you need to run `source /Users/nahua/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM 
Please consider donating to our open collective to help us maintain RVM.

  Donate: https://opencollective.com/rvm/donate


Ruby enVironment Manager 1.29.9 (latest) (c) 2009-2017 Michal Papis, Piotr Kuczynski, Wayne E. Seguin

Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.15/x86_64/ruby-2.6.3.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/nahua/.rvm/rubies/ruby-2.6.3, this may take a while depending on your cpu(s)...
ruby-2.6.3 - #downloading ruby-2.6.3, 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 13.8M  100 13.8M    0     0  4529k      0  0:00:03  0:00:03 --:--:-- 4529k
ruby-2.6.3 - #extracting ruby-2.6.3 to /Users/nahua/.rvm/src/ruby-2.6.3.....
ruby-2.6.3 - #configuring.......................................................................
ruby-2.6.3 - #post-configuration.
ruby-2.6.3 - #compiling.....................................................................
ruby-2.6.3 - #installing...........
ruby-2.6.3 - #making binaries executable..
ruby-2.6.3 - #downloading rubygems-3.0.6
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  866k  100  866k    0     0  3437k      0 --:--:-- --:--:-- --:--:-- 3437k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.6.3 - #extracting rubygems-3.0.6.....
ruby-2.6.3 - #removing old rubygems........
$LANG was empty, setting up LANG=en_US.US-ASCII, if it fails again try setting LANG to something sane and try again.
ruby-2.6.3 - #installing rubygems-3.0.6...............................................
ruby-2.6.3 - #gemset created /Users/nahua/.rvm/gems/ruby-2.6.3@global
ruby-2.6.3 - #importing gemset /Users/nahua/.rvm/gemsets/global.gems......................................................-
ruby-2.6.3 - #generating global wrappers.......
ruby-2.6.3 - #gemset created /Users/nahua/.rvm/gems/ruby-2.6.3
ruby-2.6.3 - #importing gemsetfile /Users/nahua/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.6.3 - #generating default wrappers.......
ruby-2.6.3 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.6.3 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
Creating alias default for ruby-2.6.3....

  * To start using RVM you need to run `source /Users/nahua/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
(base) ➜  ~ source /Users/nahua/.rvm/scripts/rvm
source /Users/nahua/.rvm/scripts/rvm
(base) ➜  ~ rvm
Ruby enVironment Manager 1.29.9 (latest) (c) 2009-2017 Michal Papis, Piotr Kuczynski, Wayne E. Seguin


For additional documentation please visit https://rvm.io

(base) ➜  ~ echo $PATH
/Users/nahua/.rvm/gems/ruby-2.6.3/bin:/Users/nahua/.rvm/gems/ruby-2.6.3@global/bin:/Users/nahua/.rvm/rubies/ruby-2.6.3/bin:/opt/anaconda3/bin:/opt/anaconda3/condabin:/Users/nahua/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/nahua/.rvm/bin
(base) ➜  ~ rvm -v
rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
(base) ➜  ~ rvm list
=* ruby-2.6.3 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  ~ rvm install 2.7.0
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.15/x86_64/ruby-2.7.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/nahua/.rvm/rubies/ruby-2.7.0, this may take a while depending on your cpu(s)...
ruby-2.7.0 - #downloading ruby-2.7.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 14.0M  100 14.0M    0     0  4616k      0  0:00:03  0:00:03 --:--:-- 4616k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.7.0 - #extracting ruby-2.7.0 to /Users/nahua/.rvm/src/ruby-2.7.0 - please wait
ruby-2.7.0 - #configuring - please wait
ruby-2.7.0 - #post-configuration - please wait
ruby-2.7.0 - #compiling - please wait
ruby-2.7.0 - #installing - please wait
ruby-2.7.0 - #making binaries executable - please wait
Installed rubygems 3.1.2 is newer than 3.0.6 provided with installed ruby, skipping installation, use --force to force installation.
ruby-2.7.0 - #gemset created /Users/nahua/.rvm/gems/ruby-2.7.0@global
ruby-2.7.0 - #importing gemset /Users/nahua/.rvm/gemsets/global.gems - please wait
ruby-2.7.0 - #generating global wrappers - please wait
ruby-2.7.0 - #gemset created /Users/nahua/.rvm/gems/ruby-2.7.0
ruby-2.7.0 - #importing gemsetfile /Users/nahua/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.7.0 - #generating default wrappers - please wait
ruby-2.7.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.7.0 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
(base) ➜  ~ rvm list
 * ruby-2.6.3 [ x86_64 ]
=> ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  ~ gem -v
3.1.2
(base) ➜  ~ bundle -v
Bundler version 2.1.2
(base) ➜  ~ rvm use 2.6.3
Using /Users/nahua/.rvm/gems/ruby-2.6.3
(base) ➜  ~ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin19]
(base) ➜  ~ gem -v
3.0.6
(base) ➜  ~ bundle -v
Bundler version 1.17.3
(base) ➜  ~ rvm use 2.7.0
Using /Users/nahua/.rvm/gems/ruby-2.7.0
(base) ➜  ~ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
(base) ➜  ~ gem -v
3.1.2
(base) ➜  ~ bundle -v
Bundler version 2.1.2
(base) ➜  ~ rvm install 2.6.5
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.15/x86_64/ruby-2.6.5.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/nahua/.rvm/rubies/ruby-2.6.5, this may take a while depending on your cpu(s)...
ruby-2.6.5 - #downloading ruby-2.6.5, 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 13.4M  100 13.4M    0     0  9377k      0  0:00:01  0:00:01 --:--:-- 9370k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.6.5 - #extracting ruby-2.6.5 to /Users/nahua/.rvm/src/ruby-2.6.5 - please wait
ruby-2.6.5 - #configuring - please wait
ruby-2.6.5 - #post-configuration - please wait
ruby-2.6.5 - #compiling - please wait
ruby-2.6.5 - #installing - please wait
ruby-2.6.5 - #making binaries executable - please wait
ruby-2.6.5 - #downloading rubygems-3.0.6
ruby-2.6.5 - #extracting rubygems-3.0.6 - please wait
ruby-2.6.5 - #removing old rubygems - please wait
$LANG was empty, setting up LANG=en_US.US-ASCII, if it fails again try setting LANG to something sane and try again.
ruby-2.6.5 - #installing rubygems-3.0.6 - please wait
ruby-2.6.5 - #gemset created /Users/nahua/.rvm/gems/ruby-2.6.5@global
ruby-2.6.5 - #importing gemset /Users/nahua/.rvm/gemsets/global.gems - please wait
ruby-2.6.5 - #generating global wrappers - please wait
ruby-2.6.5 - #gemset created /Users/nahua/.rvm/gems/ruby-2.6.5
ruby-2.6.5 - #importing gemsetfile /Users/nahua/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.6.5 - #generating default wrappers - please wait
ruby-2.6.5 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.6.5 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
(base) ➜  ~ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
(base) ➜  ~ gem -v
3.0.6
(base) ➜  ~ bundle -v
Bundler version 1.17.3
(base) ➜  ~ gem install rails
...
IGNORED DUE TO CHARACTER LIMIT ON Whosebug
...
Successfully installed concurrent-ruby-1.1.5

HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
But that may break your application.

If you are upgrading your Rails application from an older version of Rails:

Please check your Rails app for 'config.i18n.fallbacks = true'.
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
'config.i18n.fallbacks = [I18n.default_locale]'.
If not, fallbacks will be broken in your app by I18n 1.1.x.

If you are starting a NEW Rails application, you can ignore this notice.

For more info see:
https://github.com/svenfuchs/i18n/releases/tag/v1.1.0
...
IGNORED DUE TO CHARACTER LIMIT ON Whosebug
...
Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, zeitwerk, activesupport, rack, rack-test, mini_portile2, nokogiri, crass, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, activerecord, globalid, activejob, mini_mime, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, actionmailbox, actiontext, thor, method_source, railties, sprockets, sprockets-rails, rails after 39 seconds
40 gems installed
(base) ➜  ~ rails -v
Rails 6.0.2.1
(base) ➜  ~ rvm use 2.6.5
Using /Users/nahua/.rvm/gems/ruby-2.6.5
(base) ➜  ~ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
(base) ➜  ~ gem install rails
...
IGNORED DUE TO CHARACTER LIMIT ON Whosebug
...
Successfully installed concurrent-ruby-1.1.5

HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
But that may break your application.

If you are upgrading your Rails application from an older version of Rails:

Please check your Rails app for 'config.i18n.fallbacks = true'.
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
'config.i18n.fallbacks = [I18n.default_locale]'.
If not, fallbacks will be broken in your app by I18n 1.1.x.

If you are starting a NEW Rails application, you can ignore this notice.

For more info see:
https://github.com/svenfuchs/i18n/releases/tag/v1.1.0

...
IGNORED DUE TO CHARACTER LIMIT ON Whosebug
...
Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, zeitwerk, activesupport, rack, rack-test, mini_portile2, nokogiri, crass, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, activerecord, globalid, activejob, mini_mime, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, actionmailbox, actiontext, thor, method_source, railties, sprockets, sprockets-rails, rails after 34 seconds
40 gems installed
(base) ➜  ~ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
(base) ➜  ~ rvm list
 * ruby-2.6.3 [ x86_64 ]
=> ruby-2.6.5 [ x86_64 ]
   ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  ~ rvm use 2.7.0
Using /Users/nahua/.rvm/gems/ruby-2.7.0
(base) ➜  ~ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
(base) ➜  ~ rvm use 2.6.5
Using /Users/nahua/.rvm/gems/ruby-2.6.5
(base) ➜  ~ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
(base) ➜  ~ cd projects/rails/DevcampPortfolio
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ cat .ruby-version
2.7.0
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ rvm list
 * ruby-2.6.3 [ x86_64 ]
   ruby-2.6.5 [ x86_64 ]
=> ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ rails c
Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`.
Could not find minitest-5.14.0 in any of the sources
Run `bundle install` to install missing gems.
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ clear
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ which bundle
/Users/nahua/.rvm/rubies/ruby-2.7.0/bin/bundle
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ bundle install
Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`.
Fetching gem metadata from https://rubygems.org/............
...
### BUNDLE INSTALL...DELETING DUE TO CHARACTER LIMIT ON Whosebug
...
Bundle complete! 15 Gemfile dependencies, 67 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ gem install bundler:2.1.4
Fetching bundler-2.1.4.gem
Successfully installed bundler-2.1.4
Parsing documentation for bundler-2.1.4
Installing ri documentation for bundler-2.1.4
Done installing documentation for bundler after 2 seconds
1 gem installed
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ rvm use 2.6.5
Using /Users/nahua/.rvm/gems/ruby-2.6.5
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ rvm use 2.7.0
Using /Users/nahua/.rvm/gems/ruby-2.7.0
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ rails c
Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`.
Running via Spring preloader in process 16581
Loading development environment (Rails 6.0.2.1)
2.7.0 :001 > exit
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ cd ../../20bn-homepage
(base) ➜  20bn-homepage git:(master) rvm list
 * ruby-2.6.3 [ x86_64 ]
=> ruby-2.6.5 [ x86_64 ]
   ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  20bn-homepage git:(master) bundle install
You must use Bundler 2 or greater with this lockfile.
(base) ➜  20bn-homepage git:(master) bundle -v
Bundler version 1.17.3
(base) ➜  20bn-homepage git:(master) gem install bundler:2.1.4
Fetching bundler-2.1.4.gem
Successfully installed bundler-2.1.4
Parsing documentation for bundler-2.1.4
Installing ri documentation for bundler-2.1.4
Done installing documentation for bundler after 2 seconds
1 gem installed

(base) ➜  20bn-homepage git:(master) bundle install
You must use Bundler 2 or greater with this lockfile.
(base) ➜  20bn-homepage git:(master) bundle -v
Bundler version 1.17.3
(base) ➜  20bn-homepage git:(master) gem install bundler:2.1.4
Fetching bundler-2.1.4.gem
Successfully installed bundler-2.1.4
Parsing documentation for bundler-2.1.4
Installing ri documentation for bundler-2.1.4
Done installing documentation for bundler after 2 seconds
1 gem installed
(base) ➜  20bn-homepage git:(master) bundle install
...
### BUNDLE INSTALL...DELETING DUE TO CHARACTER LIMIT ON Whosebug
...
Bundle complete! 61 Gemfile dependencies, 180 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Post-install message from postmark:

    ==================
    Thanks for installing the postmark gem. If you don't have an account, please
    sign up at http://postmarkapp.com/.

    Review the README.md for implementation details and examples.
    ==================
  %

(base) ➜  20bn-homepage git:(master) exit
Last login: Wed Jan 22 10:05:43 on ttys001
(base) ➜  ~ rvm list
zsh: command not found: rvm
(base) ➜  ~ echo "source $HOME/.rvm/scripts/rvm" >> ~/.zshrc
(base) ➜  ~ source ~/.zshrc
(base) ➜  ~ rvm list
=* ruby-2.6.3 [ x86_64 ]
   ruby-2.6.5 [ x86_64 ]
   ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  ~ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin19]
(base) ➜  ~ cd projects/rails/DevcampPortfolio
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ rvm list
 * ruby-2.6.3 [ x86_64 ]
   ruby-2.6.5 [ x86_64 ]
=> ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ rails c
Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`.
Running via Spring preloader in process 26256
Loading development environment (Rails 6.0.2.1)
 :001 > Blog.last
  Blog Load (2.5ms)  SELECT "blogs".* FROM "blogs" ORDER BY "blogs"."id" DESC LIMIT   [["LIMIT", 1]]
 => #<Blog id: 12, title: "My great blog title", body: "Lorem ipsum blah blah blah", created_at: "2020-01-21 09:49:26", updated_at: "2020-01-21 09:49:26", slug: "my-great-blog-title">
 :002 > exit
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ cd ../../20bn-homepage
(base) ➜  20bn-homepage git:(master) rvm list
 * ruby-2.6.3 [ x86_64 ]
=> ruby-2.6.5 [ x86_64 ]
   ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  20bn-homepage git:(master) ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
(base) ➜  20bn-homepage git:(master) rails c
Loading development environment (Rails 6.0.2.1)
 :001 > exit
(base) ➜  20bn-homepage git:(master) cd ../rails/DevcampPortfolio
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ echo "export RUBYOPT='-W:no-deprecated -W:no-experimental'" >> ~/.zshrc
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ source ~/.zshrc
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ rails c
Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`.
Running via Spring preloader in process 26693
Loading development environment (Rails 6.0.2.1)
2.7.0 :001 > exit
(base) ➜  DevcampPortfolio git:(portfolio-feature) ✗ cd ../../20bn-homepage
(base) ➜  20bn-homepage git:(master) ruby -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)

### COMMENT OFF export RUBYOPT='-W:no-deprecated -W:no-experimental' IN ~/.zshrc AGAIN

(base) ➜  20bn-homepage git:(master) source ~/.zshrc
(base) ➜  20bn-homepage git:(master) ruby -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  20bn-homepage git:(master)
(base) ➜  20bn-homepage git:(master) rvm list
Warning! PATH is not properly set up, /Users/nahua/.rvm/gems/ruby-2.6.5/bin is not at first place.
         Usually this is caused by shell initialization files. Search for PATH=... entries.
         You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
         To fix it temporarily in this shell session run: rvm use ruby-2.6.5
         To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
 * ruby-2.6.3 [ x86_64 ]
=> ruby-2.6.5 [ x86_64 ]
   ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  20bn-homepage git:(master) rvm get stable --auto-dotfiles
...
IGNORED DUE TO Whosebug CHARACTER LIMIT
...

RVM reloaded!

(base) ➜  20bn-homepage git:(master) ruby -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)


(base) ➜  20bn-homepage git:(master) echo $PATH
/Users/nahua/bin:/usr/local/bin:/Users/nahua/.rvm/gems/ruby-2.6.5/bin:/Users/nahua/.rvm/gems/ruby-2.6.5@global/bin:/Users/nahua/.rvm/rubies/ruby-2.6.5/bin:/Users/nahua/.rvm/bin:/Users/nahua/bin:/usr/local/bin:/Users/nahua/bin:/usr/local/bin:/opt/anaconda3/bin:/opt/anaconda3/condabin:/Users/nahua/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
(base) ➜  20bn-homepage git:(master) rvm reset
Warning! PATH is not properly set up, /Users/nahua/.rvm/gems/ruby-2.6.5/bin is not at first place.
         Usually this is caused by shell initialization files. Search for PATH=... entries.
         You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
         To fix it temporarily in this shell session run: rvm use ruby-2.6.5
         To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
(base) ➜  20bn-homepage git:(master) ruby -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  20bn-homepage git:(master) rvm list
 * ruby-2.6.3 [ x86_64 ]
   ruby-2.6.5 [ x86_64 ]
   ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  20bn-homepage git:(master) source ~/.zshrc
(base) ➜  20bn-homepage git:(master) ruby -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  20bn-homepage git:(master) rvm use ruby-2.6.5
Using /Users/nahua/.rvm/gems/ruby-2.6.5
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  20bn-homepage git:(master) rvm use 2.7.0
Using /Users/nahua/.rvm/gems/ruby-2.7.0
(base) ➜  20bn-homepage git:(master) ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]

原问题描述:

我有两个项目,一个使用 ruby-2.7.0,另一个使用 ruby-2.6.5

我刚刚意识到我在最新的 OS X 上的 Ruby/Rails 设置有一个奇怪的问题。每次我使用 rvmrbenv安装了 ruby 的两个版本,最终只有一个版本可以运行 (2.7.0)。 bundle 以及另一个上的 gem 命令将不再有效,但会给出 Traceback....(RuntimeError).

在过去的 6 个小时里,我重新安装了 rbenv,卸载了 rbenv,安装了 rvm。我还尝试卸载所有非系统 Ruby 版本和 Rails。似乎没有任何帮助。

以下是我的控制台中显示的错误:

(base) ➜  ~ rvm list
=* ruby-2.6.5 [ x86_64 ]
   ruby-2.7.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

(base) ➜  ~ bundle -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  ~ gem -v
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)
(base) ➜  ~ rvm use 2.7.0
Using /Users/nahua/.rvm/gems/ruby-2.7.0
(base) ➜  ~ bundle -v
Bundler version 2.1.4
(base) ➜  ~ rvm use 2.6.5
Using /Users/nahua/.rvm/gems/ruby-2.6.5
Traceback (most recent call last):
ruby: invalid option -:  (-h will show valid options) (RuntimeError)

我遇到了完全相同的问题,除了将 rbenv 与 bash 一起使用。

肇事者似乎是你.zsh 文件中的 echo "export RUBYOPT='-W:no-deprecated -W:no-experimental'" 行,我不确定 Ruby 2.6.5 是否理解它。

从您的 .zsh / .bashrc / .profile 中删除 echo "export RUBYOPT='-W:no-deprecated -W:no-experimental'" 并重新启动您的 shell.