This is a guide for those setting up Ruby environments on a Mac, either for the first time or just again on a new machine.
First make sure you’ve dealt with your priors, for example getting your terminal in shape. Here’s a checklist I wrote last week for that. We’ll immediately be using those tools, so go through that first.
Next you will need some common libraries. If you’re a developer, you’d almost certainly need these anyway, regardless of Ruby. Run the following commands in your terminal:
brew install gmp
brew install gnupg
These are using our new packet manager homebrew to install gmp and gnupg. The latter handles security signatures. We’re going to use it to get the encryption keys for Ruby Version Manager. Run the following command in your terminal:
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
This is taken straight from the RVM homepage.
After that, installing the latest versions of Ruby and Rails, along with a system to switch to different versions, is as easy as a single line:
\curl -ssl https://get.rvm.io | bash -s stable — rails
In this line, we install RVM, Ruby, and Rails. This line is also taken directly from the RVM homepage.
curl is a command-line tool for transferring data. In our case, we’re using it to get an installer.
The \ isn’t really necessary; what it does is override any aliases you might have set. You probably don’t have anything aliased to “curl”, but on the off-chance you did, the backslash makes this a safer command. (Here’re a couple of previous blog post to learn more about aliases).
-ssl attempts to create a secure (SSL) connection.
https://get.rvm.io is the URL we’re getting data from. You can click it and directly see the installer code, if you like!
It will install RVM; the additional instructions we’ve given it will install the latest stable builds of Ruby and Rails.