How to Install Ruby on Mac: Simple Steps for Beginners
To install
Ruby on a Mac, the easiest way is to use Homebrew by running brew install ruby in the Terminal. Alternatively, you can download the official Ruby installer from ruby-lang.org and follow the setup instructions.Syntax
Use the Terminal app on your Mac to run commands. The main command to install Ruby with Homebrew is:
brew install ruby: This tells Homebrew to download and install the latest Ruby version.ruby -v: This checks the installed Ruby version to confirm installation.
bash
brew install ruby ruby -v
Output
ruby 3.2.2p53 (2024-03-30 revision 12345) [x86_64-darwin22]
Example
This example shows how to install Ruby using Homebrew and verify the installation.
bash
brew install ruby ruby -v
Output
Updating Homebrew...
==> Downloading ruby-3.2.2.tar.gz
==> Installing dependencies...
==> Installing ruby...
==> Installation successful!
ruby 3.2.2p53 (2024-03-30 revision 12345) [x86_64-darwin22]
Common Pitfalls
Some common mistakes when installing Ruby on Mac include:
- Not having Homebrew installed before running
brew install ruby. You can install Homebrew from brew.sh. - Using the system Ruby version instead of the newly installed one. Make sure your
PATHincludes Homebrew's Ruby path, usually/usr/local/opt/ruby/binor/opt/homebrew/opt/ruby/binon Apple Silicon Macs. - Not restarting the Terminal after installation, so the new Ruby is not recognized.
Example of wrong and right usage:
bash
# Wrong: Using system Ruby ruby -v # Right: Using Homebrew Ruby export PATH="$(brew --prefix ruby)/bin:$PATH" ruby -v
Output
ruby 2.6.3p62 (system default)
ruby 3.2.2p53 (Homebrew installed)
Quick Reference
| Command | Purpose |
|---|---|
| brew install ruby | Install Ruby using Homebrew |
| ruby -v | Check Ruby version |
| brew update | Update Homebrew before installing |
| export PATH="$(brew --prefix ruby)/bin:$PATH" | Add Homebrew Ruby to PATH |
| which ruby | Show Ruby executable location |
Key Takeaways
Use Homebrew to install Ruby easily with the command
brew install ruby.Always check your Ruby version after installation using
ruby -v.Make sure Homebrew is installed before trying to install Ruby.
Add Homebrew's Ruby path to your
PATH environment variable to use the new Ruby.Restart your Terminal after installation to apply changes.