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.
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.
[[email protected]]# 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 −
[[email protected] ~]$ git clone https://github.com/rbenv/rbenv.git
[[email protected] ~]$ https://github.com/rbenv/ruby-build.git ruby-build will provide installation features to rbenv −
Note − We need to switch to root or an administration user before running install.sh
[[email protected] ruby-build]$ cd ~/ruby-build
[[email protected] ruby-build]# ./install.sh
Let’s set our shell for rbenv and assure we have installedthe correct options.
[[email protected] ~]$ source ~/rbenv/rbenv.d/exec/gem-rehash.bash
[[email protected] ruby-build]$ ~/rbenv/bin/rbenv
Some useful rbenv commands are −
|local||Sets or shows the local application-specific Ruby version|
|global||Sets or shows the global Ruby version|
|shell||Sets or shows the shell-specific Ruby version|
|install||Installs a Ruby version using ruby-build|
|uninstall||Uninstalls a specific Ruby version|
|rehash||Rehashes rbenv shims (run this after installing executables)|
|version||Shows the current Ruby version and its origin|
|versions||Lists all Ruby versions available to rbenv|
|which||Displays the full path to an executable|
|whence||Lists all Ruby versions that contain the given executable|
Let’s now install Ruby −
[[email protected] bin]$ ~/rbenv/bin/rbenv install -v 2.2.1
After compilation completes −
[[email protected] ~]$ ./ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
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.
[[email protected] 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.
[[email protected] rdc]# ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
Leave a Comment