CentOS - Ruby on Rails

In the CentOS setup articles (page 1 and page 2) we secured, updated and personalized the install to add some working software.

We also installed the development tools package. Now we can go ahead and install Ruby on Rails.


Process

The process will involve a mix of installation methods - the main ruby packages and dependencies will be installed using the 'yum' package manager, but rubygems will be installed from source.

The reason for this is that rubygems is not readily available through the repositories in yum . To get the latest and most stable version of rubygems onto the Slice we need to install from source.

Ruby

Let's go ahead and install ruby.

For now, we'll stick to the basics and get the main Ruby on Rails packages installed:

sudo yum install ruby ruby-devel ruby-irb ruby-rdoc ruby-ri

Version

Once done, we can have a look at the Ruby version:

ruby -v
...
ruby 1.8.5 (2006-08-25) [x86_64-linux]

Good, now we can move onto installing rubygems for our Rails installation.

Rubygems

As mentioned, we're going to install rubygems from source.

Let's go ahead and download the source code into our sources directory. If you haven't got a sources directory, you can simply create one:

mkdir ~/sources
cd ~/sources

At the time of writing the latest rubygems version is v1.3.1.

As normal, please check for the latest release on the rubygems homepage.

Let's download v1.3.1:

wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz

Now unpack it and move into the newly created folder:

tar xzvf rubygems-1.3.1.tgz
cd  rubygems-1.3.1

Now we can go through the simple process of compiling it:

sudo ruby setup.rb

Version

Once done, we can check the gem version with a:

gem -v
...
1.3.1

Good.

Update

We need to do a quick update to rubygems:

sudo gem update

Although nothing will change as we have installed the latest version, a '--system' update will ensure everything is the latest and greatest:

sudo gem update --system

Rails

Continuing with the Rails installation, we can go ahead and install it:

sudo gem install rails

Once completed, you can check what gems were installed with a:

sudo gem list

Which gives the following (from a fresh Slice and no other gems installed):

*** LOCAL GEMS ***

actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activeresource (2.3.2)
activesupport (2.3.2)
rails (2.3.2)
rake (0.8.4)

Done.

Sqlite3

Rails version 2.0+ uses sqlite3 as its default database - you can, of course, use other databases and indeed, there will be articles specifically aimed at other databases.

We need to first install the necessary sqlite development package before installing the gem. Note the base sqlite package should already be installed on a fresh slice.

sudo yum install sqlite-devel

Now we can install the gem as follows:

sudo gem install sqlite3-ruby

Let's do a simple test to see if the module is working:

irb
#irb(main):001:0> 
require 'rubygems'
=> true
#irb(main):002:0> 
require 'sqlite3'
=> true

If the result does not return 'true' the you may have missed a step.

Postfix and Subversion

Finally, we need to install postfix and subversion so we can 'check-out' plugins and send mail from our Rails applications:

sudo yum install postfix subversion -y

Answer the postfix questions as you see fit but the defaults usually suffice for our purposes as we are only using it to send emails and not for receiving mail.

Note subversion may have previously been installed as part of the Development Tools groupinstall process in our CentOS Setup - Page 2 article.

That's it

You now have a Ruby on Rails and postfix/subversion stack setup and ready to roll.

Now you are ready to install the web server of your choice whether that be Litespeed, Nginx or Apache.

Article Comments:

Dan Maurin commented Sat Jun 27 15:02:40 UTC 2009:

Thank you for the easy install for Ruby on my Asterisk (trixbox) CentOS system.

Everything work great except for installing the sqlite3-ruby.

/usr/bin/ruby extconf.rb checking for main() in -lsqlite... no checking for sqlite.h... no * extconf.rb failed * Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.

Alpha Monk commented Thu Aug 06 21:09:43 UTC 2009:

I looked at some better ranking tutorials about installing RoR and getting everything up and running. I now know those blogs where written by folks who could not have actually installed RoR or where so experience that they left out important steps that were not obvious to me.

This is a very tutorial on install RoR on a Linux computer. BTW this tutorial works just fine for RHEL 5u3.

Shane Beacom commented Thu Aug 20 18:56:08 UTC 2009:

Since the current version of Ruby is 1.9.1 I ran in to a few issues getting Sqlite3 and thin working.

To build from the source with 1.9.1

  1. Start with the first step of RubyGems
  2. Download the latest source (1.9.1) to your sources folder.

wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz

  1. extract the files move to the new folder.

tar xzvf ruby-1.9.1-p243.tar.gz cd ruby-1.9.1-p243

  1. Configure, Make and Install from the source.

./configure –enable-pthread make make install

  1. Create a link from the installed ruby location to your usr/bin folder

ln -s /usr/local/bin/ruby /usr/bin/ruby

You can carry on now using ruby 1.9.1 for the rest of the articles on here.

dave commented Wed Jan 13 21:55:34 UTC 2010:

Hello,

Only been on slicehost for a few hours, but enjoying it so far.

I followed the instructions above but got into trouble later when i tried to install msyql gems* - seems the version of ruby (1.8.5) that's installed above is too old to work w/ the mysql gems.. Any idea how to get around this? do i have to compile ruby from source?

thanks! -D

trecords commented Wed Feb 03 14:36:13 UTC 2010:

Hi, I have newly moved from shared host to VPS and these articles helped me muchmore to configure the server. All commands works without "sudo" at the begining of the commands.

Thanks.

Adamquadmon commented Fri Feb 05 21:41:11 UTC 2010:

I've followed the tutorial and try to upgrade to 1.9.1 as Shane Beacom wrote but after make install, and a lot of time, doing ruby -v i get

Adamquadmon commented Fri Feb 05 21:41:12 UTC 2010:

I've followed the tutorial and try to upgrade to 1.9.1 as Shane Beacom wrote but after make install, and a lot of time, doing ruby -v i get ruby 1.8.5

Adamquadmon commented Fri Feb 05 21:42:26 UTC 2010:

sorry for the double post... any help?

Adamquadmon commented Fri Feb 05 22:16:47 UTC 2010:

ok, found error, /usr/bin/ruby was ruby 1.8.5, rm this and link the /usr/local/bin/ruby one solve the issue

Kris commented Sat Apr 24 03:17:52 UTC 2010:

Followed this article fine, but had problems with Ruby version.. with the error "ERROR: Expected Ruby version" >= 1.8.6, is 1.8.5"

Found the solution here: http://www.centos.org/modules/newbb/viewtopic.php?topic_id=11821

daniel joo commented Fri May 07 04:35:35 UTC 2010:

Hi, Great post. I got the same error as most of you but was able to install RUBY 1.9.1 with Shanes comment. The only thing I changed was compiling the make file. I used ./configure && make instead of ./configure –enable-pthread make. Thanks for all your help

Jay commented Tue Aug 24 03:55:40 UTC 2010:

Very nicely done. Saved me a few hours on a new server.

Sidenote: not a customer but the well thought out presentation of this information will probably result in my being one. Both of my current server hosts could care less about helping me implement ROR

Thanks.

sulo commented Thu Nov 18 09:42:36 UTC 2010:

With CentOS 5.4/5 sudo gem install sqlite3-ruby will give you some error complaining about sqlite3 version. The easy fix for this is to use gem install with --version '=1.2.5' or the like to fix it.

so, sudo gem install sqlite3-ruby -- -version '=1.2.5' should solve the problem.

Honza commented Thu Dec 23 10:40:37 UTC 2010:

I have problem at the step with Gem intallation. I installed Gem, but when I try to enter gem -v or other command with "gem", I will get error message like this:

/usr/local/lib/ruby/siteruby/1.9.1/rubygems.rb:267:in config_file': undefined methoduserhome' for Gem:Module (NoMethodError) from /usr/local/lib/ruby/siteruby/1.9.1/rubygems/configfile.rb:157:in config_file_name' from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:121:ininitialize' from /usr/local/lib/ruby/siteruby/1.9.1/rubygems/gemrunner.rb:51:in new' from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:51:indo_configuration' from /usr/local/lib/ruby/siteruby/1.9.1/rubygems/gemrunner.rb:27:in run' from /usr/local/bin/gem:21:in<main>'

What is wrong? My Ruby version is 1.9.2 and OS CentOS 5.5

TGarcia commented Fri Feb 11 01:10:46 UTC 2011:

I am attempting to install redmine on this particular server (I have done so in another 3 other machines), but after I installed ruby 1.8.7 (from source), zlib using yum, etc. In the process, I had to install, reinstall, uninstall things a few times and then I got this error. Can anyone help me with this. How do I go about troubleshooting this? This also happens when I run $ gem list --local command.

Server data: CentOS 5.5 x64 ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux] [tgarcia@template ~]$ rpm -qa | grep zlib zlib-1.2.3-3 zlib-devel-1.2.3-3 zlib-1.2.3-3 zlib-devel-1.2.3-3


ERROR DATA:

[tgarcia@template ~]$ sudo gem install i18n /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb:31:in gem_original_require': no such file to load -- zlib (LoadError) from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/package.rb:10 from /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb: 31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/format.rb:9 from /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb: 31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/installer.rb:11 from /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb: 31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/ dependency_installer.rb:3 from /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb: 31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/commands/ install_command.rb:4 from /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb: 31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/siteruby/1.8/rubygems/commandmanager.rb: 167:in load_and_instantiate' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb: 88:in[]' from /usr/local/lib/ruby/siteruby/1.8/rubygems/commandmanager.rb: 144:in find_command' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb: 131:inprocess_args' from /usr/local/lib/ruby/siteruby/1.8/rubygems/commandmanager.rb: 102:in run' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:58:inrun' from /usr/local/bin/gem:21 [tgarcia@template ~]$ gem list --local /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb:31:in gem_original_require': no such file to load -- zlib (LoadError) from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/siteruby/1.8/rubygems/specfetcher.rb:1 from /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb: 31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/commands/ query_command.rb:3 from /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb: 31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/commands/ list_command.rb:2 from /usr/local/lib/ruby/siteruby/1.8/rubygems/customrequire.rb: 31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 31:inrequire' from /usr/local/lib/ruby/siteruby/1.8/rubygems/commandmanager.rb: 167:in load_and_instantiate' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb: 88:in[]' from /usr/local/lib/ruby/siteruby/1.8/rubygems/commandmanager.rb: 144:in find_command' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb: 131:inprocess_args' from /usr/local/lib/ruby/siteruby/1.8/rubygems/commandmanager.rb: 102:in run' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:58:inrun' from /usr/local/bin/gem:21

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)