So previously when we were setting up Rails we installed Ruby, so in this post we are going to go over how you would update your Ruby version.

As you may remember, we are using rbenv to manage our Ruby versions, installed on top of Homebrew. Yes, Ruby hit 4.0 - the following lines install it (check ruby-lang.org for the latest patch version) and set it as your default:

brew update

brew upgrade ruby-build

rbenv install 4.0.6

rbenv global 4.0.6

# version should be >= Ruby 4.0
ruby -v

If rbenv install claims the version doesn’t exist, your ruby-build is out of date - the brew upgrade ruby-build line is doing the heavy lifting there.

One extra step I always do after switching versions: cd into each project and run bundle install again, since gems are installed per Ruby version. If a project isn’t ready for Ruby 4 yet, just drop a .ruby-version file in it with the older version and rbenv handles the rest.

And that’s it, you’ve updated Ruby to the latest version.