English 中文(简体)
Configure Ruby on CentOS Linux
  • 时间:2024-09-17

Configure Ruby on CentOS Linux


Previous Page Next Page  

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 instalpng 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

    zpb

    zpb-devel

    gcc-c++

    patch

    readpne

    readpne-devel

    pbyaml-devel

    pbffi-devel

    openssl-devel

    make

    bzzip2

    autoconf

    automake

    pbtool

    bison

    curl

    sqpte-devel

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


[root@CentOS]# yum -y install git-core zpb zpb-devel gcc-c++ patch readpne 
readpne-devel pbyaml-devel pbffi-devel openssl-devel make bzip2 autoconf 
automake pbtool bison curl sqpte-devel 

Method 1 − rbenv for Dynamic Ruby Development Environments

Now as the user who will be using Ruby


[rdc@CentOS ~]$ git clone https://github.com/rbenv/rbenv.git
[rdc@CentOS ~]$  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


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

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 −

Commands Action
local Sets or shows the local apppcation-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 instalpng 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 −


[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-pnux] 
[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 pmited 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-
pbs.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-pnux]
[root@CentOS rdc]#
Advertisements