How do I install Ruby on a Mac with Homebrew and rbenv?
Install rbenv and its ruby-build plugin with Homebrew, run rbenv init once, open a new Terminal window, then install a Ruby version with rbenv install and choose it with rbenv global. Afterwards ruby -v should print that version, and which ruby should point inside your rbenv folder. Never use sudo to install gems.
Cite
Poignant Guide Ruby Q&A, "How do I install Ruby on a Mac with Homebrew and rbenv?", https://poignantguide.net/answers/read/how-do-i-install-ruby-on-a-mac-with-homebrew-and-rbenv/, accessed 2026-11-15.- Fenwick HaleStaffStaff: gems, Rails, tooling and debugging ·
The short version
A version manager is a tool that keeps several Ruby versions on one machine and picks one for you. rbenv is one such tool, and Homebrew is a package manager for the Mac that installs command line programs. The Ruby site's install page lists rbenv among the managers and notes that rbenv cannot install Ruby by itself, so it pairs with the ruby-build plugin. Open Terminal and run these in order:
brew install rbenv ruby-build rbenv initClose the Terminal window and open a new one. The rbenv README says to do this so the changes take effect. Then:
rbenv install -l # lists the latest stable versions rbenv install 3.3.6 # use a version from that list rbenv global 3.3.6 # make it your default ruby -v # => ruby 3.3.6 (...) which ruby # => /Users/you/.rbenv/shims/rubyThe version number 3.3.6 is only an example. Pick one that
rbenv install -lshows on your machine. The compile step can take several minutes, and that is normal because ruby-build compiles Ruby from source.Prefer to check your Mac first? The README tells you to confirm that your build environment has the necessary tools and libraries before running rbenv install. If the build fails, read the error before you retry, and search the message in the ruby-build discussions that the README links.
Why it works
When you type ruby, your shell looks through the folders in your PATH (the ordered list of places it searches for programs) and runs the first match. After rbenv init, the folder
~/.rbenv/shimscomes first in that list. According to the README, any call to ruby, gem or bundler then activates rbenv, which looks for a.ruby-versionfile in your project folder and runs the version named there, or your global version if there is no such file.That also explains the
rbenv localcommand. Running it inside a project folder writes a.ruby-versionfile, so that one project can use a different Ruby from the rest of your machine:cd my-first-project rbenv local 3.3.6 cat .ruby-version # => 3.3.6Which way should I install Ruby?
Option What you get Watch out for The Ruby that came with macOS Something already on the machine The Ruby site notes it is included by default, but you do not control its version, and gem installs may ask for sudo brew install rubyThe newest Ruby, in one command One Ruby at a time, so switching per project is harder rbenv with ruby-build Many versions, one per project if you wish One extra setup step, and compile time The Ruby site also lists RVM, chruby and other managers. Any of them is fine; this answer uses rbenv because the steps are short.
Mistakes beginners make
- Skipping the new Terminal window. The shell reads its startup file when a window opens. Without a fresh window, ruby still points at the old Ruby.
- Using sudo for gems. The README says you should not use sudo to install gems. If you see a "you don't have write permissions" error, it is likely that your system Ruby is still the global default. Run rbenv global with your version and try again.
- Installing a version and never selecting it. rbenv install only downloads and compiles. Until you run rbenv global or rbenv local, the system Ruby may still answer.
- Editing the startup file by hand and getting it wrong. On rbenv 1.3.0 and later, rbenv init edits your shell startup file for you, so a second hand-written copy is rarely needed.
Check this in order
- Run
brew --version. If the command is not found, install Homebrew first from its own website. - Run
rbenv --version. If it is not found, rerunbrew install rbenv ruby-build. - Run
grep rbenv ~/.zshrc. You should see a line added by rbenv init. (macOS uses zsh by default; if you use bash, look in~/.bash_profileinstead.) - Open a new Terminal window and run
rbenv versions. An asterisk marks the active version. - Run
rbenv which rubyto see the exact file rbenv will run. - Run
ruby -vandwhich ruby. If the path does not contain.rbenv/shims, go back to step 3.
When ruby -v looks right, start irb and try a line. The guide's Expansion Pak 1 walks through IRB, and What is Ruby? tells you what you installed.
Checked on 12 November 2026.
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.
1 answer
- Odile MarchettiStaffStaff: Ruby basics, objects and the Poignant Guide ·
A small tip from the classroom side: after rbenv global, make a file called hello.rb containing puts "hello" and run ruby hello.rb. Seeing your own program print a word is the best proof the install works, and it gives you a first file to edit while you read the guide. If the guide's older examples print warnings, that is normal, since it was written in 2005 for a much older Ruby.