Binocode

Ruby 1.9.2 installation from source on Ubuntu

by Pawel Barcik

There are easier ways to install most up to date version of Ruby on your system , for e.g. RVM or rbenv but if you want to have full control over what are you installing because it will be your production system, then this post will show you how to do this.

To install Ruby from source you need to install some dependencies first

apt-get update

apt-get -y install build-essential zlib1g zlib1g-dev libxml2 libxml2-dev libxslt1-dev sqlite3 libsqlite3-dev locate git-core libssl-dev openssl

apt-get -y install curl wget

apt-get -y install libreadline-dev

apt-get -y install libz-dev

apt-get -y install libssl-dev

apt-get -y install g++ libstdc++6-4.4-dev

apt-get -y install libxml2-dev

apt-get -y install mysql-client

apt-get -y install libmysql++-dev

apt-get -y install libmysql++3

apt-get -y install tk tk-dev

Now you are ready to install the actual ruby binaries

TMP_RUBY=1.9.2-p290
TMP_RUBY_FAMILY=1.9

cd /usr/local/src/

# remove any old source code
rm -r ruby-*

# fetch the code
wget http://ftp.ruby-lang.org/pub/ruby/$TMP_RUBY_FAMILY/ruby-$TMP_RUBY.tar.gz

#unpack it
tar -xozf ruby-$TMP_RUBY.tar.gz

cd ruby-$TMP_RUBY

mkdir /opt/rubies

./configure --disable-install-doc --prefix=/opt/rubies/ruby-$TMP_RUBY

# OPENVZ note - adjust the vps configuration , especially the PRIVVMPAGES because compilation may fail silently sometimes

# adjust the number of jobs to match the bumber of CPU cores you have 
make -j4

# OPENVZ note
# tests sometimes fail in VPS-es because of lack of resources: sockets, memory etc.
# adjust the configuration , especially the KMEMSIZE 
# and use "cat /proc/user_beancounters" to check the counters
make test

make install

After this installation all the ruby binaries will be located at /opt/rubies/ruby-1.9.2-p290/bin

Ruby code includes gem binary which is usually outdated so to update this binary run this command

gem update --system

Now everything is installed and ready for use if you have /opt/rubies/ruby-1.9.2-p290/bin in your system PATH. If not then add this

PATH=/opt/rubies/ruby-1.9.2-p290/bin:$PATH 

to /root/.bash_profile (for root only) and /etc/profile (for all except root)

in /etc/profile do not add anything below

umask 022

at the bottom of the file


← Back to Overview

comments powered by Disqus