Installing Ruby(MacOS)
Installing Ruby(MacOS)
MacOS usually ships with Ruby already, albeit older versions of Ruby. You’ll need to download a newer version of Ruby. Easiest way to do this would be to use Homebrew.
Installing Homebrew
Refer to Installing Homebrew (MacOS).
Installing Ruby
Homebrew is required to be installed for either path of installing Ruby.
Install Ruby, by either using homebrew (which will install the latest version of Ruby by default) or mise-en-place (which will let you pick which versions of Ruby to install and let’s you switch between versions easily).
With homebrew
- Run the following command in your terminal:
1
$ brew install ruby
- The terminal will prompt you to run some post-installation commands, which involve adding lines to you ~/.zshrc file (if the file doesn’t exist, create it using
$ touch ~/.zshrc). Run what will most likely be the following commands:1 2 3 4
$ export PATH="/opt/homebrew/lib/ruby/gems/3.4.0/bin:$PATH" $ export PATH="/opt/homebrew/opt/ruby/bin:$PATH" $ export LDFLAGS="-L/opt/homebrew/opt/ruby/lib" $ export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
- Done.
With mise-en-place
- Run the following commands in your terminal:
1 2 3
$ brew install mise $ echo 'eval "$(mise activate zsh)"' >> ~/.zshrc $ eval "$(mise activate zsh)"
- After that, you can install Ruby through mise (this sets the global ruby default on your computer to version 3.4.3):
1
$ mise use -g ruby@3.4.3
- If you’re wanting to use different versions of Ruby for different projects, you can use the mise trust command in the root of each project:
1 2
# while inside the root directory of a project $ mise trust
- Done.
Alternatives
Other routes for installing Ruby include the following:
- rbenv
- RVM
- asdf
- chruby
Checking your Ruby version
Whatever path you take to install Ruby, run the following command to see which version of Ruby you’re working with:
1
$ ruby -v
This post is licensed under CC BY 4.0 by the author.