On CentOS 6.5, the default version of Ruby installed is 1.8.7. Some Ruby applications require Ruby version 1.9 and higher, so they cannot run properly on stock CentOS. To upgrade Ruby on CentOS, you can build and install Ruby from the source.
If you already installed ruby and ruby-devel packages with yum before, remove them first before upgrading Ruby.
Build and install the latest Ruby from the source as follows.
$ sudo yum install openssl-devel
$ wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz
$ tar xvfvz ruby-2.1.2.tar.gz
$ cd ruby-2.1.2
$ sudo make install
Finally, update Rubygems and Bundler.
$ sudo gem install bundler
If you have any pre-installed gems with an older version of Ruby, update the gems.
To use the installed Ruby/Rubygems, open a new terminal. Then check the version of installed Ruby and Rubygems as follows.
$ rubygems --version
1. When I run gem command after upgrading Ruby, I get the following error.
ERROR: While executing gem ... (Gem::Exception) Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
To fix this problem, you need to build and install Ruby extension for OpenSSL from the source as follows.
$ cd ruby-2.1.2/ext/openssl/
$ ruby extconf.rb
$ make top_srcdir="../../"
$ sudo make install top_srcdir="../../"
Subscribe to Ask Xmodulo
Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!