Latest Ruby version not showing up in RVM?

I just realized I’m running an out-of-date version of Ruby (1.9.3-p327), and browsed to the Ruby website to find out what the latest, stable version is. It turns out 1.9.3-p362 is the latest version:

2013-01-03_23-13-57

When I tried to install this version via RVM, RVM complained it could not find the binaries for it, and threw the following error:
2013-01-03_23-14-54

Well, that doesn’t seem right. Lets list the versions of Ruby that RVM knows about:

$ rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p371]
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p320]
[ruby-]1.9.3-p125
[ruby-]1.9.3-p194
[ruby-]1.9.3-p286
[ruby-]1.9.3-[p327]
[ruby-]1.9.3-head
[ruby-]2.0.0-preview2
ruby-head

No version 1.9.3-p362 in that that list, huh? Lets update RVM to obtain the latest stable release with the “rvm get stable” command:
2013-01-03_23-16-05

Now that’s more like it. Lets see what “rvm list known” shows us now:

$ rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p371]
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p320]
[ruby-]1.9.3-p125
[ruby-]1.9.3-p194
[ruby-]1.9.3-p286
[ruby-]1.9.3-p327
[ruby-]1.9.3[-p362]
[ruby-]1.9.3-head
[ruby-]2.0.0-preview2
ruby-head

Annnd there’s the 1.9.3-p362 version, ready for installation with the usual “rvm install ruby-1.9.3-p362” command.

Install Ruby Version Manager (RVM) on CentOS 5.5

RVM, or Ruby Version Manager is a popular and effective way to manage running multiple Ruby environments. Here is how you set it up on CentOS 5.5:

1) Add the Webtatic respository and install Git.

rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
yum install --enablerepo=webtatic git

(Note that this command will also install the perl-Error and perl-Git dependencies)

2) Create an rvm user and group.

groupadd rvm
useradd -g rvm rvm

3) Add the root user to the rvm group (required for installation)

usermod -a -G rvm root

4) Install RVM as root.

bash < <(curl -L http://bit.ly/rvm-install-system-wide)

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5840  100  5840    0     0   1620      0  0:00:03  0:00:03 --:--:--  5653
Group 'rvm' exists, proceeding with installation.
Adding 'root' to the group 'rvm'
Creating the destination dir and making sure the permissions are correct
Cloning into rvm...
remote: Counting objects: 4206, done.
remote: Compressing objects: 100% (2029/2029), done.
Receiving objects:  26% (1094/4206), 796.00 KiB | 54 KiB/s

....

Setting up group permissions
Generating system wide rvmrc
Generating /usr/local/lib/rvm to load rvm
Correct permissions on rvmrc and the rvm loader
RVM is now installed. To use, source '/usr/local/lib/rvm' to your shell profile.

5) Install zlib via RVM.

# rvm package install zlib
Fetching zlib-1.2.5.tar.gz to /usr/local/rvm/archives
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  531k  100  531k    0     0   206k      0  0:00:02  0:00:02 --:--:--  226k
Extracting zlib-1.2.5.tar.gz to /usr/local/rvm/src
Configuring zlib in /usr/local/rvm/src/zlib-1.2.5.
Compiling zlib in /usr/local/rvm/src/zlib-1.2.5.
Installing zlib to /usr/local/rvm/usr

6) Install Ruby 1.9.2 using RVM.

# rvm install 1.9.2 -C --with-zlib-dir=/usr/local/rvm/src/
Installing Ruby from source to: /usr/local/rvm/rubi

                while depending on your cpu(s)...

ruby-1.9.2-p180 - #fetching
ruby-1.9.2-p180 - #extracting ruby-1.9.2-p180 to /u
ruby-1.9.2-p180 - #extracted to /usr/local/rvm/src/
ruby-1.9.2-p180 - #configuring
ruby-1.9.2-p180 - #compiling
ruby-1.9.2-p180 - #installing
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby
Installation of rubygems completed successfully.
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby
Installation of rubygems completed successfully.
ruby-1.9.2-p180 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.2-p180 - #importing default gemsets (/usr/local/rvm/gemsets/)
Install of ruby-1.9.2-p180 - #complete

7) Set the RVM default to version 1.9.2

# rvm --default use 1.9.2
Using /usr/local/rvm/gems/ruby-1.9.2-p180

&#56&#41 Verify that Ruby version 1.9.2 was installed successfully.

# ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]

9) Add this environment variable to root’s .bash_profile file.

[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"

10) Install rails.

# gem install rails
Fetching: activesupport-3.0.5.gem (100%)
Fetching: builder-2.1.2.gem (100%)
Fetching: i18n-0.5.0.gem (100%)
...
Installing RDoc documentation for railties-3.0.5...
Installing RDoc documentation for bundler-1.0.10...
Installing RDoc documentation for rails-3.0.5...< /pre>

UPDATE 7/25/2011: The system-wide install script is no longer available on github, and has been removed by the author. A workaround link is posted in the comments on this Stack Overflow discussion.

Installing Phusion Passenger on CentOS 5.5

Need to run Rails apps under Apache?  Phusion’s Passenger is becoming the de-facto standard for doing so with its ease of setup, low memory footprint, and deep support.  Once you have Ruby and Rails setup on your CentOS server (see this post), you can install Passenger and integrate it with Apache.  Here’s how:

1) Install the Apache development tools
Passenger is nothing more than a dynamic shared object (DSO).  You will need the httpd-devel package to build Dynamic Shared Objects (DSOs) for Apache.  The following command will install it:

yum install httpd-devel

Depending on your server, you will notice a number of dependent packages being installed, including apr-devel, perl, and apr-util-devel.

2) Install Passenger.
Passenger is a gem, and installed in the typical fashion of any gem:

gem install passenger
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed fastthread-1.0.7
Successfully installed passenger-2.2.15
2 gems installed
Installing ri documentation for fastthread-1.0.7...
Installing ri documentation for passenger-2.2.15...
Installing RDoc documentation for fastthread-1.0.7...
Installing RDoc documentation for passenger-2.2.15...

3) Build Passenger for Apache
Passenger has a scripted installer. Start it with this command:

passenger-install-apache2-module

The first thing it will do is check its own dependencies. If you have everything in place, you will see this:

Follow the onscreen keyboard prompts from the script, and you will see build messages scroll quickly by as the binaries are built. If the build is successful, you will be presented with this final screen before the shell script exits:

4) Integrate Passenger with Apache
Before beginning, make a copy of your Apache httpd.conf file:

cp /etc/httpd/conf/httpd.conf httpd.conf.orig

Then edit the httpd.conf file and search for the LoadModules section. Add a directive at the end of this list to load the Passenger shared object. It should look like this:

Now scroll down to the end of the file, and add these lines to help the Passenger shared object find the ruby and gem binaries:

PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-2.2.15
PassengerRuby /usr/local/bin/ruby

5) Add a symlink to your app
Change to the directory specified by the server-wide DocumentRoot directive (/var/www/html) and add a symlink to your Rails application. In this case, our Rails application lives in the /webapps/todos directory, so the symlink should link to the “public” directory of the application:

ln -s /webapps/todos/public/ todos

6) Add a virtual host directive for your Rails application
Point Apache to your Rails application:


    ServerName localhost
    DocumentRoot /var/www/html
    RailsEnv development
    
        Allow from all
        Options -MultiViews
    
     RailsBaseURI /todos

Now restart Apache with an “apachectl restart” command, and browse to your Rails app.  That’s it!

7 Steps to Rails on CentOS

Red Hat Linux (and its recompiled cousin, CentOS)  has a fantastic reputation for stability and maturity.  However, this often means that packages included with the OS are somewhat out-of-date by the time the distribution is released.  For example, the latest version of CentOS is 5.5, and the version of Ruby that ships with it is version 1.8.5, which dates back to August 2006.  Even the Ruby group recommends using nothing less than 1.8.7 for Rails development.

So how do you get the stability of Red Hat with the goodness of Ruby? Compile from source to get the latest, greatest version.  Here’s how:

1)  Install CentOS 5.5
To save yourself alot of headaches during the installation, check to see if you have the “Development Tools” group installed with this command:

# yum grouplist |grep -i Development

If you don’t have it, install the package group with this command:

#yum groupinstall "Development Tools"

Note that you may also have the older version of Ruby installed via RPM’s.  You can check to see if you have it with this command:

# rpm -qa |grep ruby

If you discover an older version, uninstall it before proceeding (rpm -e <package_name>).

2) Create a /sources directory and change to that directory.

3) Download and build Ruby.
Download the latest Ruby source code (latest version is 1.9.2-p0 as of this writing).

wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz

Uncompress the tarball and build Ruby:

tar -zxvf ruby-1.9.2-p0.tar.gz
cd ruby-1.9.2-p0
./configure
make
make install

If you have all the proper dependencies, you should have no errors during the configure or make phases. This will install Ruby to the following directories:

/usr/local/include/ruby
/usr/local/bin/ruby
/usr/local/lib/ruby
/usr/local/share/doc/ruby/html
/usr/local/share/man1

Once the install is complete, verify the version of Ruby:

# ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036)

The Ruby source package also installs RubyGems, the Ruby package manager.  Verify the version of RubyGems:

# gem -v
1.3.7

4) Check for updated gems
Ensure you have the latest gem versions by running this command:

# gem update --system

5) Install the rake build language

# gem install rake

6) Install rails

# gem install rails

7) List the installed gems.

# gem list

That’s it! You now have a fully-installed Ruby on Rails stack.  However, Ruby also needs a back-end database and a web server for its presentation layer.   Future posts will detail how to install and integrate web server and database tiers with Rails.

Ruby

My first install of Ruby on Rails on Linux is now complete.  Would that be RoRoL?