Install Ruby 3 ⚙️ 💎
Linux
$ sudo apt-get update
$ sudo apt-get install ruby ruby-dev
macOS
$ brew install ruby@3.0
Set up Ruby path ➡️
In the case of macOS, you'll have to add this to your PATH
to run the custom Ruby.
If you had Ruby 2 running before you can leave this as is when using Ruby 3.
export PATH="/usr/local/opt/ruby/bin:PATH"
Note that both ruby
and bundler
exist there.
$ which ruby bundler
/usr/local/opt/ruby/bin/ruby
/usr/local/opt/ruby/bin/bundler
Test with:
$ ruby -v
$ bundle -v
Set up gems path 📦
This is to allow user level gems to run from anywhere.
If you like to install gems at the shared system level, like this, then you can skip this step.
$ gem install GEM_NAME
$ # OR
$ sudo gem install GEM_NAME
But if you like to install gems at the user level, like this, then you do need this step.
$ gem install GEM --user-install
Add the following to .bashrc
or .zshrc
file:
if which ruby >/dev/null && which gem >/dev/null; then
GEM_PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin"
export PATH="$GEM_PATH:$PATH"
fi
Then start a new terminal tab to load the changes.
That shell command will figure out that path to your user gems, like this:
~/.local/share/gem/ruby/3.0.0/bin
Then it will add the path to your PATH
variable.
The best part is that it is dynamic - it does not have a hard-coded path. So Ruby can change where it decides to install gems (like it did between Ruby 2 and 3 from ~/.gem
to ~/.local
). And you can upgrade from Ruby 3.0 to 3.1 or 4.0. Yet the shell command will figure out the correct path, without needing a manual update or causing head scratching when Ruby projects break one day.
Top comments (0)