Skip to content

Instantly share code, notes, and snippets.

@semperos
Created June 18, 2012 19:56
Show Gist options
  • Save semperos/2950373 to your computer and use it in GitHub Desktop.
Save semperos/2950373 to your computer and use it in GitHub Desktop.
Normal, Linux way to install Ruby for production

Ruby install in production environment

(Text ommitted)

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.

(From http://www.lone-gunman.be/en/blog/ruby-install-in-production-environment.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment