I recently had to walk through a client on how to install Ruby on Rails on his machine. It made me realize that it’s not exactly a straightforward process. I’ll go over how to install Ruby on Rails step by step on a Mac OS.
The instructions found here can be followed on the Mac OS (or OS X if you haven’t upgraded in awhile). I know that there are posts that show you how to install Ruby on Rails on specific version of the Mac operating system, but I’ve found the steps to be more or less the same in my experience.
Just FYI, all of the commands will be run in the bash terminal. They should work automatically without any problems on zshell too. If you’re on fish, you may have to modify things around a bit, especially when you install RVM (ruby version manager).
1. Install Homebrew
If you’re a developer, you probably have this installed already, but go ahead and install Homebrew if you don’t have this installed yet. For those who don’t know what Homebrew is, it’s just a package manager for Mac OS, kind of like “apt” in Debian based Linux distributions.
Follow the directions in https://brew.sh/
At the time of this writing, it says to run this command in your terminal.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. Install xcode-select
You need to have the command line tools for XCode installed. Even if you think you already have this, run this command in your terminal:
This may take some time to install. Be patient and let the installation finish. Once finished, move onto the next step.
3. Install libxml2
Nokogiri is a Ruby gem that also happens to be a dependency of Ruby on Rails. The thing is, nokogiri gem installation will fail if you don’t have libxml2 installed. You can install this with homebrew by running
brew install libxml2
4. Install RVM and a Ruby version
RVM stands for Ruby version manager. There are two major ones, RVM and rbenv. It’s preferable to use a version manager because it’ll separate the ruby installation that you use for actual development work from the one that’s installed directly on your system. This makes it easy to manage gems as well as various different ruby versions that you may encounter when you work on different Rails applications.
Both RVM and rbenv work fine, but I like RVM mostly because that’s what I’m used to. I’m going to recommend installing RVM here because that’s what I use, but it really doesn’t matter which ruby version manager you use. If you strongly prefer rbenv, go ahead and install that one.
As far as installing RVM, you can find the directions on their website https://rvm.io/
If you don’t feel like searching through the website for installation directions, just run this in your terminal.
\curl -sSL https://get.rvm.io | bash -s stable --ruby
If you get some error that says that you don’t have curl, you can install curl via homebrew
brew install curl
Once you have installed RVM, install the Ruby version you need via RVM. For example, if you need to install Ruby version 2.4.1 (current latest version at the time of this writing), you can install this via running this command in your terminal.
rvm install 2.4.1
5. Install bundler and Rails
Once you have installed RVM and a Ruby version via RVM, install the gem bundler via the command
gem install bundler
After you install bundler you can finally install Rails by running
gem install rails
Or you can cd into a Rails project directory and run
and bundler will install the correct Rails version and all required dependencies for you.
6. Optional – Install MySQL and/or PostgreSQL
You’ll notice that many Rails projects will be using MySQL or PostgreSQL. You can install these two databases with ease via Homebrew. The commands to install them are just
brew install mysql
brew install postgresql
AAAND that should be it! If you have any questions about installing Rails on your machine, feel free to leave a comment or email me at email@example.com