Site icon Michaël Rigart

Ruby install in production environment

In this article, I’ll explain how I’ve installed ruby on my production server. I only focus on ruby this time. Later on, I’ll make an article on Nginx and perhaps some security measurements I’ve taken.

Ruby 1.9.3 MRI

First things first, the ruby version I’m using for all my software is ruby 1.9.3 MRI. There was a time I ran everything using Ruby Enterprise Edition, but since MRI hit the 1.9.3 branch I made the switch. Why? Let’s just say 1.9.3 is better in performance then its predecessors and also then REE. Since there won’t be an REE version of the 1.9 branch (no huge improvements), I just switched and never looked back.

Secondly, I don’t need multiple ruby versions running at the same time. Since I’m in control of all the software, it’s easy enough to keep everything 1.9 compatible. I’m a huge fan of using rbenv in development, but using things like rbenv or RVM in production seems such a hassle.
Don’t get me wrong, it might be worth it when you can’t afford running multiple vm’s for each ruby version, but deploying your software and maintaining such a setup asks for a more complex approach.

For some background info, I’m running Ubuntu Server 10.04 LTS, but normally the compilation should work fine on all distributions. To install the essentials, check you distro for more information regarding those packages. Also, I have the tendency to install all self-compiled software in the /opt folder. This directory should be reserved for all software and add-on packages that are not part of the default installation.

Essentials

First install all the essential packages so we can start compiling:

sudo aptitude install build-essential zlib1g-dev libssl-dev libreadline5-dev

Yaml

Don’t forget to install the yaml library. Since it is missing from ruby we first need to install it ourselves. At this moment, version 0.1.4 is the latest release.

wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
tar xvzf yaml-0.1.4.tar.gz
cd yaml-0.1.4
./configure --prefix=/opt/yaml/yaml-0.1.4/
make
sudo make install

You will notice I install the yaml library in /opt/yaml/yaml-0.1.4. I did this, so I can upgrade easily in the near future. Say there is a new version available next time I want to upgrade ruby, then I can install the new version besides the existing one, not breaking the dependency.

Ruby

Now it’s time for ruby.

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125
./configure --prefix=/opt/ruby/ruby-1.9.3-p125 --enable-pthread --enable-shared --disable-install-doc --with-opt-dir=/opt/yaml/yaml-0.1.4/
make
sudo make install

Here you’ll see a similar action regarding the installation directory for ruby. I installed ruby 1.9.3-p125 inside the /opt/ruby folder. This way, I can upgrade ruby again without breaking older installations, in case I need to switch back.

Make the ruby binaries available from the command line. Before we do that, create a symlink that points to the current ruby version:

sudo ln -s /opt/ruby/ruby-1.9.3-p125/ /opt/ruby/ruby

This way, we don’t need to alter scripts that make use of that path when we might upgrade ruby. Just point everything to the symlink, so when you upgrade ruby, you only need to repoint the symlink to the newer version.

Head on to the cli. To make ruby related commands available, add the path of the symlink to your PATH variable:

sudo vim /etc/profile.d/ruby.sh
export PATH=/opt/ruby/ruby/bin:$PATH

Don’t forget to reload your shell, run the export command manually or exit en re-enter, so the changes make effect. The final step is to update rubygems to the latest version:

gem update --system

That’s it. Try running ruby -v from the cli to see the current ruby version. This way, you know that everything went fine.

Exit mobile version