Configure Ruby on CentOS Linux

Ruby is a great language for both web development and Linux Administration. Ruby provides many benefits found in all the previous languages discussed: PHP, Python, and Perl.

To install Ruby, it is best to bootstrap through the rbenv which allows the administrators to easily install and manage Ruby Environments.

The other method for installing Ruby is the standard CentOS packages for Ruby. It is advisable to use the rbenv method with all its benefits. CentOS packages will be easier for the non-Ruby savvy.

First, let’s get some needed dependencies for rbenv installer.

  • git-core
  • zlib
  • zlib-devel
  • gcc-c++
  • patch
  • readline
  • readline-devel
  • libyaml-devel
  • libffi-devel
  • openssl-devel
  • make
  • bzzip2
  • autoconf
  • automake
  • libtool
  • bison
  • curl
  • sqlite-devel

Most of these packages may already be installed depending on the chosen options and roles when installing CentOS. It is good to install everything we are unsure about as this can lead to less headache when installing packages requiring dependencies.

[root@CentOS]# yum -y install git-core zlib zlib-devel gcc-c++ patch readline 
readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf 
automake libtool bison curl sqlite-devel 

Method 1 โˆ’ rbenv for Dynamic Ruby Development Environments

Now as the user who will be using Ruby โˆ’

[rdc@CentOS ~]$ git clone
[rdc@CentOS ~]$

ruby-build will provide installation features to rbenv โˆ’

Note โˆ’ We need to switch to root or an administration user before running

[rdc@CentOS ruby-build]$ cd ~/ruby-build
[rdc@CentOS ruby-build]# ./

Let’s set our shell for rbenv and assure we have installedthe correct options.

[rdc@CentOS ~]$ source ~/rbenv/rbenv.d/exec/gem-rehash.bash

[rdc@CentOS ruby-build]$ ~/rbenv/bin/rbenv  
rbenv 1.1.0-2-g4f8925a 
Usage: rbenv <command> [<args>]

Some useful rbenv commands are โˆ’

localSets or shows the local application-specific Ruby version
globalSets or shows the global Ruby version
shellSets or shows the shell-specific Ruby version
installInstalls a Ruby version using ruby-build
uninstallUninstalls a specific Ruby version
rehashRehashes rbenv shims (run this after installing executables)
versionShows the current Ruby version and its origin
versionsLists all Ruby versions available to rbenv
whichDisplays the full path to an executable
whenceLists all Ruby versions that contain the given executable

Let’s now install Ruby โˆ’

[rdc@CentOS bin]$ ~/rbenv/bin/rbenv install -v 2.2.1

After compilation completes โˆ’

[rdc@CentOS ~]$ ./ruby -v 
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux] 
[rdc@CentOS ~]$

We now have a working Ruby environment with an updated and working version of Ruby 2.X branch.

Method 2 โˆ’ Install Ruby from CentOS Packages

This is the most simple method. However, it can be limited by the version and gems packaged from CentOS. For serious development work, it is highly recommended to use the rbenv method to install Ruby.

Install Ruby, needed development packages, and some common gems.

[root@CentOS rdc]# yum install -y ruby.x86_64 ruby-devel.x86_64 ruby-
libs.x86_64 ruby-gem-json.x86_64 rubygem-rake.noarch

Unfortunately, we are left with somewhat outdated version of Ruby.

[root@CentOS rdc]# ruby -v 
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
[root@CentOS rdc]#

Leave a Reply