Working as an iOS instructor at Flatiron School I became very familiar with the process of setting up brand new Macs for development. Because some of our internal tooling required Ruby 2.x, and Macs up through December 2016 ship with 1.9.3 as the default, I had to learn the upgrade process for Ruby.
Despite how simple this sounds, there doesn?t seem to exist a clear outline of the all steps necessary to install or upgrade Ruby on a fresh Mac. So for my own reference, I?ve put together some comprehensive instructions. Hopefully someone else will find them useful, too!
Here?s a quick summary of the steps we?ll need to take:
- Install Xcode/Xcode Command Line Tools
- Install Homebrew
- Install GPG
- Install RVM
- Install Ruby
Step 0: Update all the things!
Before you begin, make sure your Mac is fully up-to-date. Open up the App Store and check for any available updates or upgrades.
If you don?t have the latest version of macOS, take the time to get it. This process can take a while depending on your internet connection and how old your computer is, but it?s worth the effort. You?ll have access to the latest development tools as well as all the features to inspire your development.
Step 1: Install Xcode and the XCode Command Line Tools
The Xcode Command Line Tools provide a C language compiler needed to install Ruby. Xcode includes these tools, but whether or not you need Xcode is up to you. If you?re an iOS, macOS, or other Apple ecosystem developer you should go ahead and install Xcode.
After your system is totally updated, install Xcode from the App Store. When Xcode has been installed, go ahead and open it up and accept the license agreement. This step seems trivial, but it?s necessary to continue. You can close Xcode afterward.
If you?re upgrading Ruby without any intention of developing for iOS/macOS/etc., run the following in Terminal and proceed with any instructions that appear: $ xcode-select –install
Note: Don?t type the dollar sign. It?s a longstanding convention which indicates a command to be typed into Terminal.
Step 2: Install Homebrew
Homebrew is a package installer for macOS that allows you to easily install third-party content from your Terminal. We?ll need Homebrew to install GPG in a second. Use the following to install Homebrew:$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
Did you notice that we?re actually calling that command on the version of Ruby that already exists on your Mac? Inconsequential, as far as I know, but a tidbit I found interesting.
You can check that Homebrew is properly installed and configured by running $ brew doctor
Step 3: Install GnuPG
GnuPG, also known as GPG, is a tool used to encrypt/decrypt files and verify the authenticity of data. We?ll need this in the next step, so install GPG with Homebrew: $ brew install gnupg2
Step 4: Install and Update RVM
Ruby Version Manager, or RVM for short, as described on the RVM website is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments. Cool. After some quick setup, this will become your go-to means of keeping Ruby fresh on your system or reverting to older versions for projects that require you to do so.
The first time you do this, we need a way ensuring the RVM you?re installing is legit. To do this, download and install the mpapis public key with GPG:
$ gpg –keyserver hkp://keys.gnupg.net –recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
Michael Papis (mpapis) is the creator of RVM, and his public key is used to validate RVM downloads.
Now we?re set to safely install the latest stable build of RVM:
$ curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s stable
(Thanks, Jeff and Eamonn for the updates!)
Run $ source ~/.rvm/scripts/rvm to start using RVM without having to close and reopen Terminal.
Step 5: Install Ruby
Finally, we can install the latest and greatest version of Ruby. Do this by running $ rvm install ruby –latest. Easy! If you want to install a specific version of Ruby, simply run $ rvm install ruby-2.4.0, replacing the version number with the one you want.
There are a lot of steps here, and there?s a good chance I?ve overlooked a really simple means of installing RVM an updating Ruby. But I hope this helps someone out there who might otherwise struggle as I did to figure out all the steps necessary to set up a proper development environment on a Mac.
If you know any simpler workarounds, please let me know in the comments below! If you found this article helpful, please give it few claps and share!