Wednesday, 7 November 2012

Complete Guide to install Ruby 1.9.3 on CentOS

UPDATE: These instructions also work on Fedora 16 ( and possibly bellow; on 17+ you should have Ruby 1.9.3 on yum repos).
There are some nice guides out there, like this one, explaining how to do this, but they don't tell the complete story, especially if you're on a clean CentOS install - which is the only explanation I can come up with for the fact that other guides didn't have the same problems I had.

EDIT 11/12/2013: The version listed on the instructions bellow is a bit dated, since this post is now 13 months old, check for the latest ruby 1.9.3 patch and replace the patch number (p194) with the latest one on step 9 (wget [...] ruby-19.3-p194.tar.gz).

Steps I ended up following:

#preparing packages
$ sudo yum groupinstall 'Development Tools'
$ sudo yum install -y httpd-devel openssl-devel zlib-devel gcc gcc-c++ curl-devel expat-devel gettext-devel patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel make bzip2 zlib1g mysql-server

#compaling libyaml
$ wget
$ tar xzvf yaml-0.1.4.tar.gz
$ cd yaml-0.1.4
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
#compiling ruby 1.9.3
$ wget
$ tar xvzf ruby-1.9.3-p194.tar.gz
$ cd ruby-1.9.3-p194
$ ./configure
$ make
$ sudo make install
$ wget
$ tar xvzf rubygems-1.8.24.tgz
$ cd rubygems-1.8.24
$ sudo /usr/local/bin/ruby setup.rb

During the preparation stages a few packages may say they already installed, don't worry.
I'm not sure still if it will work with everything (like rails if that's your thing) but at least 
(Update I've installed both Rails and Sinatra without any problems on top of this setup)
I have been able to install some gems now which by other guides I followed fell short of.