Setting up Your Machine
I’d meant to include this with the book, but I couldn’t get things working right on Windows. If you’ve been able to, please post about and I’ll try to replicate and include the instructions here. For those of you on Mac OS or Linux, read on!
MacOS & Linux
It’s likely that your system came installed with a version of Ruby. It’s also likely that it came with a very old version of Ruby. For example, Mac OS X Lion, the latest operating system produced by Apple at the time of this writing, ships with a version of Ruby 1.8.7, built in January of 2010.
While we could install a more recent version, there’s usually a good reason why operating system vendors install specific versions, and updating the system’s version of Ruby could cause unforseen problems. Fortunately, the Ruby Version Manager (RVM for short) is a tool that can fix this. RVM will allow us to setup a completely isolated Ruby environment, outside of the system’s Ruby, with complete control over the gems we install. In fact, we can set up completely different sets of gems, and switch between them.
We’ll walk you through installing RVM, and creating a gemset for the purposes of running some example code that will verify that your environment is working. These will be very explicit instructions, but you should check the RVM website for the latest RVM installation instructions and documentation.
Installing General Development Tools
Before setting up RVM, you’ll need to make sure you have appropriate developer tools installed. It’s likely you have these installed already, especially if you are using Linux. You can do a quick check via:
It doesn’t matter where
gcc (the open-source Gnu C Compiler) is installed, just so long as it is. If it’s not, and you are running Linux, consult your distribution’s instructions for installing development tools. If
you are running Mac OS X, you’ll need to install XCode, which should’ve been included with your computer, but is also available as a free download from the Mac App Store.
Now that you have development tools installed, we need
to install RVM, which is done by executing a remote
If you are concerned about blindly executing code from the Internet, you can examine the installation script via
When RVM installs, it will generate a large amount of output. At the very end will be some instructions for configuring RVM in your environment. It should be a command like so:
This concatenates some code into your
.bash_profile. If you aren’t using
as your prompt, or don’t configure it in
.bash_profile, you’ll need to replace the
>> ~/.bash_profile with the correct file name.
Once you’ve done this, you need to reload your environment. It’s simplest to exit your current shell and open up a new one. You can check that things are working via:
If you do not see the output above, something’s gone wrong and you’ll need to retrace your steps. RVM’s installation instructions will help, and there is additional information on the website for troubleshooting. Next, you’ll need to install a version of Ruby.
Now that RVM is installed, we can use it to install any version of Ruby in a way that will not affect our system’s Ruby install. At the time of this writing the latest version of Ruby is 1.9.3, so let’s use that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
The output might not exactly match, but you should see something along these lines. It may take a while, since it first downloads the source code for Ruby 1.9.3, and then builds it (this is why we needed a C compiler installed in the first step). To check that things are working:
1 2 3
Again, the string might not match exactly, but you should see “1.9.3” in the version string. We’re almost ready. The last thing we need to do is learn about using Gemsets. Since we are using several open-source gems throughout the book, it’s handy to be able to install them in a “sandbox” that allows us to play around with them, but without installing them in our main, global set of gems.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
As you can see, we created two gemsets, named
testing2 and used
rvm gemset use to switch between them. In doing so,
gem only sees the gems listed in the current gemset. Further, we can see that by installing
gli in one gemset and not the other, RVM also manipulates our
PATH so that the
gli executable is available only in the gemset where
gli is installed.
I would recommend that you use a gemset for following along with the examples in the book. By doing this, if you get into a weird situation where your environment isn’t working, you can clear out your gemset with
rvm gemset delete and start fresh.
As mentioned, I was unable to get a good Windows install working. At the very least you will need to use the Ruby Installer to get Ruby on your system.
The specific troubles I had were around installing native gems using the DevKit. If you can get everything installed on a Windows 7 box, and execute the examples, please share it. Note that, at this time, Aruba doesn’t work with Windows, however everything else should.