4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rbenvでRubyのバージョンが切り替わらないときの対応

Posted at

rbenvでRubyのバージョンが切り替わらなかったので、それのメモです。

事象

rbenvでバージョンを切り替えても変わりません

$ rbenv versions
  system
  2.6.6 
* 2.7.1 (set by RBENV_VERSION environment variable)
$ rbenv global 2.6.6
$ rbenv versions
  system
  2.6.6 
* 2.7.1 (set by RBENV_VERSION environment variable)

やったこと

set by RBENV_VERSION environment variableと言われているのですが、特にどこにも書いていません。
また.zshrcexport RBENV_VERSION=2.6.6をすると、rbenvのversionはうまく変更されますが、
rubyのバージョンを確認しようとするとエラーになります。

$ rbenv versions
  system
* 2.6.6 (set by RBENV_VERSION environment variable) 
  2.7.1
$ ruby -v
/Users/naoto.koyama/.rbenv/versions/2.7.1/bin/ruby: invalid option -:  (-h will show valid options) (RuntimeError)

原因

Ruby 2.7の警告を抑制するために.zshrcに書いているRUBYOPTの設定を書いていることが原因でした

$ cat ~/.zshrc
...
export RUBYOPT='-W:no-deprecated -W:no-experimental' # <- これが原因

上記を削除してから以下のコマンドを打てばOKです

$ unset RUBYOPT
$ rbenv global 2.6.6
$ rbenv versions
  system
* 2.6.6 (set by /Users/naoto.koyama/workspace/portal/.ruby-version)
  2.7.1
$ ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin20]

参考

rbenvのrubyコマンドがすべて「invalid option -: (-h will show valid options) (RuntimeError)」それRUBYOPTが原因かも

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?