在Mac上安装了最新的Ruby,但在终端上仍然显示旧版本

dw1jzc5e  于 12个月前  发布在  Ruby
关注(0)|答案(2)|浏览(624)
Installed latest ruby but still showing old version

我已经在mac ventura上安装了最新的ruby版本,并收到了成功消息
成功安装ruby 3.2.2到/Users/myuser/.rubies/ruby-3.2.2
但是当在相同或新的终端上检查ruby --version时,我仍然在使用旧的ruby 2.6.10p210(2022-04-12修订版67958)[universal. arm 64 e-darwin 22]
我已经在bash_profile中导出了以下文件

source /opt/homebrew/opt/chruby/share/chruby/chruby.sh 

source /opt/homebrew/opt/chruby/share/chruby/auto.sh

export PATH=/usr/local/opt/ruby/bin:$PATH

有没有人能建议一下为什么最新版本没有反映在搜索ruby --version上。
在搜索“ruby --version”时,我们应该得到最新安装的ruby 3.2.2,但仍然显示2.6

zu0ti5jz

zu0ti5jz1#

当你试图通过自制软件安装ruby时,它会“只安装小桶”。keg-only是什么意思这意味着它只在自制软件的地窖里安装ruby,以避免覆盖系统预装的ruby。
如果你真的想这样做,你可以运行brew info ruby来查看如何将这个只支持小桶的ruby添加到你的PATH中并使其成为你的默认ruby的说明。但这是不推荐

建议安装ruby版本管理器,如rbenv、rvmasdf。然后你就可以使用它来安装不同的ruby版本,并在它们和系统ruby之间无缝切换。

例如,以下是如何使用homebrew安装和使用rbenv

# 1. Install rbenv and set it up:
brew install rbenv ruby-build
rbenv init
# - Follow the printed instructions to add rbenv to your PATH etc.
# - Close your terminal window and open a new one so your changes take effect.

# 2. Use rbenv to install the ruby version that you want
rbenv install 3.2.2

# 3. Set which ruby version you want to use. Two options:
rbenv global 3.2.2   # set the default Ruby version for this machine (simpler)
rbenv local 3.2.2    # set the Ruby version for this directory 

# 4. Verify that you're using the correct ruby version.
ruby -v

以下是rbenv的更多说明:

  • rbenv:安装ruby版本
  • rbenv:安装ruby gems
  • rbenv:命令参考
okxuctiv

okxuctiv2#

正如@mechnicov在评论中建议的那样,建议修改系统ruby。你可以使用asdf包管理器。安装指南link

相关问题