0
0

rbenvでRubyのバージョンを指定できてない理由はパスが通ってないからだった

Posted at

この前rbenvでRubyのバージョンを3.3.0にしたはずなのに、ruby -vで確認したら2.6.10に戻っていた。なんでだ?

$ ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]

少し前にRubyのバージョンを更新したときはここを指定してたんだよな...。
(そのときのメモに書いてあった)

$ which ruby
/Users/*username*/.rbenv/shims/ruby

rbenvでインストールしようとしたら、すでにあると言われた。

$ rbenv install 3.3.0
rbenv: /Users/*username*/.rbenv/versions/3.3.0 already exists
continue with installation? (y/N) N

rbenvのパスを通していないからか?
rbenvはどこにあるんだ?

$ which rbenv
/opt/homebrew/bin/rbenv

ここにパスを通してみると、Rubyのバージョンは変わるか?

$ echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.bash_profile
[~]$ source ~/.bash_profile
[~]$ ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]

変わらない。。。

こちらの記事
を参考に、

rbenv shimsにパスを通してみたら、、、

echo 'export PATH="$HOME/.rbenv/shims:$PATH"' >> ~/.bash_profile

おお、rubyのパスが変わっている。
Rubyのバージョンもrbenvでインストールしたほうになっている。

$ which ruby
/Users/*username*/.rbenv/shims/ruby
[~]$ ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]

shimsについてはこちらの記事で丁寧に解説されていた。

rbenvの公式リファレンスにも~/.rbenv/shimsにパスを通すことが必要と書いてあった。

Prepends ~/.rbenv/shims directory to PATH. This is basically the only requirement for rbenv to function properly.

0
0
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
0
0