Installed latest ruby on mac but still showing old in terminal

3.4k Views Asked by At
Installed latest ruby but still showing old version

I have installed latest ruby version on mac ventura and getting success message
Successfully installed ruby 3.2.2 into /Users/myuser/.rubies/ruby-3.2.2

But when checking ruby --version on the same or new terminal Then i am still getting old one ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]

i have exported below files in 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

Can anyone please suggest why the latest version is not reflecting on search ruby --version.

On search, "ruby --version" we should get latest installed ruby 3.2.2 but still showing 2.6

3

There are 3 best solutions below

1
lazy_coder On

As suggested by @mechnicov in the comments, it is recommended to alter the system ruby. you can use the asdf package manager for it. here is the installation guide link

2
nitsas On

When you try to install ruby via homebrew, it installs it "keg-only". What does keg-only mean? It means that it installs ruby only in homebrew's cellar, to avoid overriding the ruby that comes preinstalled with your system.

If you really want to, you can run brew info ruby to see instructions for how to add this keg-only ruby into your PATH and make it your default ruby. But that's not recommended!

It's recommended to install a ruby version manager, like rbenv, rvm, or asdf. Then you'll be able to use that to install different ruby versions and switch between them and the system ruby seamlessly.

For example, here's how to install and use rbenv using homebrew:

# 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

Here's more instructions for rbenv:

1
Evgeny Nalivayko On
brew install rbenv ruby-build
rbenv init
rbenv install 3.3.0
rbenv global 3.3.0
rbenv local 3.3.0
eval "$(rbenv init - bash)"
ruby -v