There used to be a time when installing Ruby and the associated Ruby on Rails web framework was a complete pain. Since then, all sorts of solutions have sprung up to make this process a little bit less painful and tedious. One of the latest is called Tokaido and makes the installation a breeze. But, it abstracts away so much from the user that what Tokaido actually does on your system can be somewhat confusing for a beginner. In this article, we’ll take a look at how to use Tokaido to get Ruby/Rails up and running, as well as what kind of stuff Tokaido brings along with it.
Please note that Tokaido is currently Mac OS X only. Sorry Linux and Windows users; you can check out RailsInstaller instead.
The Basics: Ruby Ecosystem
We’ll go through some of the basics of how the distribution of the Ruby interpreter as well as Ruby libraries (i.e. “gems”) works before taking a look at Tokaido.
When we say that Tokaido installs Ruby, we’re not being particuarly clear. It turns out that Ruby itself is just a specification of a language and there are many implementations of it, all with different versions. The canonical implementation, however, is the one available on Ruby’s website and is referred to as the MRI/YARV interpreter. There’s other implementations as well, such as JRuby or IronRuby, which all have their specific use-cases. Tokaido gives you a copy of MRI/YARV since that’s what 90%+ projects will use.
Currently, MRI/YARV has three different versioning splits. There’s 2.2.x (stable), 2.1.x (old stable) and 2.0.x (previous old stable). For most projects, you will want the 2.2.x version; fortunately, that’s what Tokaido will get you.
Before we get down to using Tokaido, it is important to understand how the Ruby world handles the distribution of code. I’m going assume a basic knowledge of how the Ruby language works but not much more.
Often, we would like to re-use code that someone else has already written, i.e. a library. For languages such as C, there is no centralized way to get a library and use it in your project. You just have to track it down and somehow include it with your project. Ruby, on the other hand, makes this process simple with a system called RubyGems. Basically, when someone writes a library, he/she organizes it in a specific format and then uploads it to a server which will keep track of it. When someone else wants to use that code, they use a client that will “install” that library locally. Dependency resolution is another benefit of using these “gems”, i.e. if we download gem “A” and it needs gem “B” to be available, the RubyGems client will automatically get gem “B” as well.
Although Ruby comes with a bunch of stuff out of the box (referred to as the Ruby Standard Library), a lot of what practicing Ruby developers use come in the from of gems. In fact, Ruby on Rails itself is generally distributed as a gem. Tokaido not only takes care of installing Ruby for us, but also the RubyGems client through which we can install Rails and friends. You should never use another package manager (e.g. Homebrew) in order to install what can be installed through RubyGems. It is far easier for a gem developer update RubyGems than it is to update RubyGems and another package manager, so the package managers often have old versions of gems which will cause odd problems when you try to run your projects.
Alright, let’s get ourselves a copy of Tokaido. Head on over to the Github download page and get the main zip file. Extract it and drag the Tokaido application to your Applications folder. Run it. You should see something like this:
If you’ve reached this point, congratulations! You have a copy of Ruby, RubyGems, etc. all ready to go on your system. In fact, you have Rails ready to go! Click on the “Open in Terminal” button and, after clicking “OK” on a dialog box, you’ll see a Terminal window. This Terminal has been loaded with a version of Ruby, the “gem” client, etc. To create a new Rails project, type in the following:
rails new projectname
You can also manage your Rails apps through Tokaido. Once you’ve created a project, click the “+” button within Tokaido in order to navigate to your Rails application folder (i.e. the folder called “projectname”) and add it to Tokaido. Once you add it in, you’ll see something like the following:
Click “Boot App” in order to run the Rails app and get a local development server running, just as you would with the command line
rails server command. In the latest version of Rails (4.1.x at the time of writing), the Puma webserver is used on port 3000.
Wrapping It Up
With a few clicks, Tokaido lets us set up Ruby, Rails, gems, etc. on a Mac OS X system. This used to be such a pain point that people coughed up $50,000 for someone to make it easier. For many Rails beginners back in the day, half of the first day of learning would be spent trying to square away the installation. Tokaido takes this problem and decimates it. Hopefully, this quick guide can help you can get Ruby/Rails up and running on your system.