Reputation: 13
See the terminal commands I used below to upgrade to the newest version of Ruby. It says at one point "ruby 3.2.0 is already installed and up to date", but when I run "ruby -v" it still returns the old version of Ruby. Am I doing something wrong?
ā ~ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
ā ~ brew install ruby
Error:
homebrew-core is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
Warning: ruby 3.2.0 is already installed and up-to-date.
To reinstall 3.2.0, run:
brew reinstall ruby
ā ~ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
ā ~ brew reinstall ruby
==> Fetching ruby
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.2.0
Already downloaded: /Users/Madeline/Library/Caches/Homebrew/downloads/c360900acacef49e831b0f640b0e175180c181ef83afbcd24d4d6609fbf146fe--ruby-3.2.0.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:c25553dfc94e9
Already downloaded: /Users/Madeline/Library/Caches/Homebrew/downloads/f587974e09ec9fbb07b125260da3ce05b66e91a92ec27898f2e446b81a840b88--ruby--3.2.0.monterey.bottle.tar.gz
==> Reinstalling ruby
==> Pouring ruby--3.2.0.monterey.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/3.2.0/bin
You may want to add this to your PATH.
ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH, run:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
For compilers to find ruby you may need to set:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
For pkg-config to find ruby you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
==> Summary
šŗ /usr/local/Cellar/ruby/3.2.0: 16,574 files, 44.8MB
==> Running `brew cleanup ruby`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
ā ~ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
ā ~
I expected "ruby -v" to return the newest version (3.2.0) after I had run the command "brew reinstall ruby". It is still returning the old version.
Upvotes: 1
Views: 766
Reputation: 107077
When installing Ruby with Homebrew, brew will not make the installed version make your default Ruby version on the system automatically because that would override system Ruby that might be using by your operating system.
The is explained in the after install message:
==> Caveats
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/3.2.0/bin
You may want to add this to your PATH.
ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH, run:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
For compilers to find ruby you may need to set:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
For pkg-config to find ruby you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
That said: When you want to use the new Ruby version, then you need to follow the steps from that message and need to set or reconfigure the environment variables like described. When done, you will need to restart your terminal (or even the machine) to take those changes into effect.
Overriding system Ruby, and not being able to switch between different versions of Ruby, is often seen as a bad practice. Therefore, people usually suggest using a Ruby version manager, that offers more flexibly. You might want to look into Ruby version managers like rbenv, RVM or Ruby plugin for asdf version manager.
Upvotes: 3