Rubies

As Wikipedia says, RubyMotion is an implementation of the Ruby programming language. OS X already ships with Ruby installed, but its version is outdated and has some problems. In this chapter, we are going to update Ruby and install Ruby Version Management tool.

There are lots of Ruby version management tools available. RVM, Chruby, Rbenv. Their primary task is to manage multiple Ruby versions: switch between Ruby versions, install or remove them, etc. In this tutorial we are going to install Rbenv - it is a lightweight and easy-to-use version manager. The installation process is straightforward, and you can follow it on their Github page or do it here.

Since you already have Homebrew, you can install rbenv with a couple of commands:

brew update
brew install rbenv ruby-build

These commands will install Rbenv and ruby-build tools. After, you will need to inject "rbenv init" command into your shell profile. You do it just once during installation, so it is fine if it sounds unfamiliar. However, I will try to explain what does it mean:

Each time you open a terminal, it loads some shell. By default, OS X uses Bash as its shell. There are other shells, like zsh, fish, etc. Shell's profile is a configuration file. It just automatically runs some number of commands for you. We are going to add "rbenv init" command there, so it will be executed automatically each time you open a terminal. It is fine not to add this command to this file - everything will still work, but you will need to run "rbenv init" by yourself each time you open new terminal tab or window.

So, let's add this command into our shell profile. If you did not install alternative shells, just use next command.

echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Otherwise, you will need to figure our how to run rbenv init automatically in your shell by yourself.

This is it! We have Ruby Version Management system installed. Let's install Ruby now.

Rbenv

Let's learn the main rbenv commands:

Updates

To update Ruby to latest version, we need to update rbenv and ruby-build first, so it will have an up-to-date list of Ruby versions. But to do it, we need to update Homebrew first: brew update.

And now we can upgrade rbenv and ruby-build with brew upgrade rbenv ruby-build.

Now, when you have info about all latest Ruby versions, you can list them with rbenv install -l, and install whatever you want with rbenv install RUBY_VERSION (don't forget to replace RUBY_VERSION with actual Ruby version you would like to install). Make sure to run rbenv rehash after installation, and make new version default one, if needed.

Ruby has been installed, and now we can move to the next chapter.

Book Index | Next