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 https://www.ruby-lang.org/en/downloads/ 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 http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
$ 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 http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
$ tar xvzf ruby-1.9.3-p194.tar.gz
$ cd ruby-1.9.3-p194
$ ./configure
$ make
$ sudo make install
#rubygems
$ wget http://rubyforge.org/frs/download.php/76073/rubygems-1.8.24.tgz
$ 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.