sharp bites

standing on the shoulders of giants

Setting up your ruby environment on Linux

Here are the instructions on how to set up a ruby environment for Linux, in case you want to start playing with it.

NOTE: Don’t use the packages from your distribution. They are outdated and will cause more harm than good. Use one of the methods below.

The quick and easy way
If you are planning to use Rails anyways, you can use the script from railsready.
It will install rails, passenger, and a shitload dependencies it need for everything to work smoothly.
You can install it by running:
sudo wget –no-check-certificate https://github.com/joshfng/railsready/raw/master/railsready.sh && bash railsready.sh
The script will ask if you want to build Ruby from source or install RVM. Choose RVM.

It will download around 50MB of libraries from the repositories and then download and compile rvm, ruby and download again some other gems, so it will take some time. Don’t worry, you don’t have to do anything, just wait.

The almost-as-quick, almost-as-easy way
If you don’t intend to use rails and don’t feel like installing all that stuff, use the following method. It’s basically doing the same thing as the previous script, except you don’t need so many dependencies, and you won’t install rails or passenger.

Installing RVM

RVM (Ruby Version Manager) is a tool which allows us to easily install, manage and work with multiple ruby environments (interpreters and gems) on the same machine. This means we can create different environments with distincts versions, of ruby, rails, or whatever gem we want, without any headaches.

In order to install rvm, you’ll need curl, git and some compiler tools. We can get them with the following command:
sudo apt-get install git-core curl build-essential
To install rvm execute:
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
This command will install rvm in your home directory.
You need to include a line at the end of the .bashrc file to tell it to load rvm.
Follow carefuly the instructions on your terminal, specially the part about converting the return to an if statement
”[ -z “$PS1” ] && return”
NOTE: The railsready script doesn’t do this, and just appends the line loading rvm at the end of the file. RVM maintainers recommend otherwise, so you better do it their way.

If you find any problems, check rvm site troubleshooting information (section ‘Trhoubleshooting your install’)

Finally reload your envirnonment executing:
source ~/.bashrc
Installing ruby
Now you have rvm installed and running, you can proceed to install ruby. You’ll need some packages first, the following command will tell you which:
rvm notes
In my case, these were:
# For Ruby (MRI & ree)  you should install the following OS dependencies:
sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf
Now, we can install ruby 1.9.2:
rvm install 1.9.2
This will take a while, since it is dowloading ruby sources and compiling them.

You can check ruby is all fine and dandy by running
ruby -v
You should get something similar to:
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux]
On the next post I will explain how to setup your environment for testing using rvm.

Comments