Ubuntu Hardy - Ruby on Rails

In the Ubuntu Hardy setup articles (page 1 and page 2) we secured, updated and personalised the install ready to add some working software.

We also installed the build-essential package. Now we can go ahead and install Ruby on Rails.


Update

This articles has been updated to use the latest (at the time of writing) version of rubygems which is v1.2.0.

This version of rubygems has finally fixed the memory issues seen on smaller Slices.

You can now install, update and administer all your rubygems from within a 256Slice with no issues.

Process

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

The reason for this is that it is important to get the latest and most stable version of rubygems onto the Slice and the easiest way to do that is by installing from source.

Ruby

Let's go ahead and install ruby. Note the install command shown below includes the sqlite3 db package.

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.

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

sudo aptitude install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby sqlite3 libsqlite3-ruby1.8

Symlink

We need to create some symlinks from the install to locations every programme would look:

sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby
sudo ln -s /usr/bin/ri1.8 /usr/bin/ri
sudo ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc
sudo ln -s /usr/bin/irb1.8 /usr/bin/irb

Version

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

ruby -v
...
ruby 1.8.6 (2007-09-24 patchlevel 111) [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.

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.2.0.

As mentioned above, this release fixes the memory issues found with earlier versions of rubygems.

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

Let's download v1.2.0:

wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz

Now unpack it and move into the newly created folder:

tar xzvf rubygems-1.2.0.tgz
cd  rubygems-1.2.0

Now we can go through the simple process of compiling it and creating a symlink:

sudo ruby setup.rb
...
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Version

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

gem -v
...
1.2.0

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.1.0)
actionpack (2.1.0)
activerecord (2.1.0)
activeresource (2.1.0)
activesupport (2.1.0)
rails (2.1.0)
rake (0.8.1)

Done.

sqlite3 test

Now we can do a simple test to see if the sqlite3 module is working:

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

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 aptitude 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.

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 server of your choice whether that be Litespeed, Nginx or Apache.

PickledOnion.

Article Comments:

PeterG commented Thu May 01 20:48:40 UTC 2008:

I did sudo gem install rails

without the following --no-rdoc --no-ri

how do I now remove rdoc and ri

PickledOnion commented Fri May 02 09:20:30 UTC 2008:

Peter,

You don't need to remove them if they are installed.

When you add the --no-rdoc and --no-ri options to the install all it does is leave those parts out so the main rails gems can be installed on smaller Slices.

Having them installed is a good thing so you don't need to worry.

PickledOnion

Daniel Nogues commented Thu May 08 10:07:17 UTC 2008:

To install Rmagick I run these commands:

sudo aptitude install libmagick9-dev ... sudo gem install rmagick

To test the installation I run:

irb

irb(main):001:0>require 'RMagick'

However, instead of true I get:

LoadError: no such file to load -- RMagick

Despite this error, I can run my site which requires rmagick.

Why the error then?

PickledOnion commented Thu May 08 10:09:21 UTC 2008:

Hi Daniel,

I am not sure: this articles doesn't tackle installing rmagick so isn't related to what I have written here.

You may be better off with a forum post.

PickledOnion

giorgi commented Fri May 09 13:30:27 UTC 2008:

Hi Daniel, try this way: irb -r rubygems

require 'RMagick' => true

or irb

require 'rubygems' => true require 'RMagick' => true

Randy commented Mon May 12 22:59:27 UTC 2008:

I was able to get rmagick to install on Ubuntu 8.0.4 using these instructions.

https://bugs.launchpad.net/ubuntu/+source/librmagick-ruby/+bug/220811/comments/9

Peter commented Tue May 13 15:09:33 UTC 2008:

I got Rmagick going using these simple instructions:

sudo apt-get install imagemagick

sudo apt-get install libmagick9-dev

sudo gem install rmagick

From http://www.enrailed.net/2008/05/02/installing-imagemagick-rmagick-on-ubuntu-hardy-heron/

Daniel Nogues commented Tue May 13 21:55:29 UTC 2008:

Thank you for all comments. Giorgi solution worked for me.

arthur commented Thu May 22 03:41:43 UTC 2008:

sudo aptitude install postfix subversion -y

My installation of postfix and subversion fails after I am popped into a postfix configuration application that neither allows me to make a selection, nor exit gracefully. Am I using the wrong interface (Putty from a PC)? Any thoughts?

Joc commented Sat May 24 09:10:18 UTC 2008:

Hi,

I have installed Hardy on my slice and set it up as per your instructions for the purpose of running rails apps with mod_rails. Everything is running great apart from the app (redmine) doesn't seem to be sending emails. I tried to look through the PostFix documentation but it's gibberish to the likes of me. Any ideas?

Melvin Ram commented Fri May 30 06:34:34 UTC 2008:

Arthur, you need to hit the tab button on your keyboard to select Ok and then it will let you make a selection.

Raymond Brigleb commented Sun Jun 22 16:13:47 UTC 2008:

The problem I keep having is this:

user@host:~/sources$ sudo gem install rails --no-rdoc --no-ri Bulk updating Gem source index for: http://gems.rubyforge.org/ ERROR: could not find rails locally or in a repository

I've worked around it by adding --source and the gems.rubyonrails.org URL, but then it complains about a lack of 'rake'...

Tadatoshi commented Sun Jun 22 16:51:03 UTC 2008:

RubyGems 1.2.0 is released yesterday.

wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz

Ed Ruder commented Sun Jun 22 18:48:03 UTC 2008:

I'm having a problem on a 256M slice--after downloading and building Rubygems successfully, I run "sudo gem update" to update all gems installed to the latest. gem then runs its memory usage up to 265M or so, starts swapping like mad, and never completes (before I kill it a few hours later in frustration).

The "gem update" goes so far as to output "Bulk updating Gem source index for: http://gems.rubyforge.org/", but nothing else.

When I've run "gem update" on other boxes, it: a) starts displaying "." characters pretty quickly, as it downloads new gem entries, and b) never takes more than a few minutes to complete.

I followed this tutorial, so I've got v1.1.0 and I did not do a "gem update --system".

I'm going to try to re-install Rubygems (once I figure out how to uninstall it), but I don't have high expectations that that will solve my problem.

Any thoughts? Thanks in advance!

Ed

Ed Ruder commented Sun Jun 22 19:46:56 UTC 2008:

Thanks, Tadatoshi--I uninstalled Rubygems 1.1.0, installed 1.2.0, and had no problems!

Runar commented Sun Jun 22 20:15:00 UTC 2008:

@Ed I had the same problem on my 256 slice with the same installation versions. After deciding to upgrade to 512 (I think I'll need the extra juice anyway) the gem update process actually completes in a few minutes, but it still uses memory "like mad" (as you said) when it's running. I'm not sure if this is related, but I was unable to install passenger with RubyGems 1.1.0 as well..

Anyway, I just upgraded to RubyGems 1.2.0 following Tadatoshi's link above and everything seems to be working fine now (updating is done in a flash, "passenger" is being installed as we speak, even the rain outside has stopped ;-)

I wouldn't be able to tell you precisely whether it was resizing my slice or upgrading RubyGems that did the trick, but I suggest you try upgrading RubyGems first as this is cheaper than resizing (although I'm not saying SliceHost is expensive!)

Raymond Brigleb commented Sun Jun 22 20:20:35 UTC 2008:

Indeed, going to Rubygems 1.2.0 did the trick for me as well. Thanks!

ryanb commented Fri Jul 04 17:49:13 UTC 2008:

Praise Rubygems 1.2. Worked like a charm. Thanks so much for writing and maintaining all of these articles!

Anita Kuno commented Fri Jul 04 18:25:01 UTC 2008:

I used these instructions on a new install of hardy on my laptop. My comments may or may not apply to servers.

I had to add libyaml-ruby and libzlib-ruby prior to installing rubygems and add build essential before downloading gems in order to get things to work for me.

Thanks for the great articles, Pickled Onion.

Chris W commented Thu Jul 10 17:47:02 UTC 2008:

This tutorial worked for me on my 256 MB slice, however, when I try and require 'sqlite3' from irb I get the following:

no such file to load -- sqlite3.

Any ideas on how to fix it? I know you state in the tutorials that I've done something wrong, but everything else matches up.

yudix commented Sat Jul 19 04:51:28 UTC 2008:

hi friend please help me.. I've download the latest version of rubygems and follow the instructions above but when I execute :

sudo ruby setup.rb

this error was appeared

./lib/rubygems/spec_fetcher.rb:1:in require': no such file to load -- zlib (LoadError) from ./lib/rubygems/spec_fetcher.rb:1 from ./lib/rubygems/source_index.rb:10:inrequire' from ./lib/rubygems/source_index.rb:10 from ./lib/rubygems.rb:767:in require' from ./lib/rubygems.rb:767 from setup.rb:22:inrequire' from setup.rb:22

please help me :(

Stuart commented Sat Jul 19 20:28:01 UTC 2008:

I found rake wasn't automatically installed with rails . So I needed to do an additional:

sudo gem install rake

Xiong commented Wed Jul 30 15:33:11 UTC 2008:

here is the solution to yudix's problem: http://lucaschan.com/weblog/2007/03/22/installing-ruby-on-rails-on-centosredhat-4x/

Marc commented Tue Aug 05 01:54:40 UTC 2008:

Hello Group,

How can I install an earlier version of rails?

Nick commented Thu Aug 07 21:13:33 UTC 2008:

Marc:

sudo gem install rails -v 1.2.6

replace 1.2.6 with the version you want

Tanner Lovelace commented Fri Aug 29 20:41:50 UTC 2008:

Thanks for a good howto. One suggestion I'd make, though, is that instead of just doing symbolic links from ruby1.8 -> ruby (etc...) you could add them to the alternatives system. That way, if you later decided you wanted ruby 1.9 you could simply add that to the alternatives and then switch between them easily. To use alternatives instead of symlinks, you'd use these commands:

sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.8 1 sudo update-alternatives --install /usr/bin/ri ri /usr/bin/ri1.8 1 sudo update-alternatives --install /usr/bin/rdoc rdoc /usr/bin/rdoc1.8 1 sudo update-alternatives --install /usr/bin/irb irb /usr/bin/irb1.8 1

Tanner Lovelace commented Fri Aug 29 20:42:23 UTC 2008:

sigh Sorry about the messed up markup above. :-(

Dan Zitting commented Fri Oct 17 04:29:22 UTC 2008:

Out of date again as gems 1.3.0 is out. Instructions work fine though, just switch 1.2.0 to 1.3.0

PickledOnion commented Fri Oct 17 10:35:04 UTC 2008:

Hi,

The article is likely to be out of date as soon as it is written. Thankfully the gems are in continual development so we get to see improvements all the time.

Thanks for letting us know it works with 1.3.0

PickledOnion

marvin commented Wed Oct 22 04:46:51 UTC 2008:

Make sure everybody that when you downloading rubygems you just don't change 1.2.0 to 1.3.0

http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz

is the right url, notice the 43895 that is not the same for the 1.2.0 version.

Bryan commented Mon Nov 03 23:16:19 UTC 2008:

Hello,

Great article. Do you have to do anything to have rails recognize the installed gems path. Some gems listed using "gem list" can not be found be rails when I attempt to use them.

The details are listed in this forum post.

http://forum.slicehost.com/comments.php?DiscussionID=2556&page=1#Item_0

Thanks,

Bryan

Lawrence commented Fri Nov 07 01:54:27 UTC 2008:

Be aware that with ubuntu 8.10 the first command will install ruby v1.8.7. This may be undesirable as rails 2.1.x does not support that version. If you need to downgrade to v1.8.6 see http://ubuntuforums.org/showthread.php?t=964978

Michael commented Wed Nov 26 06:21:33 UTC 2008:

Good work! God I love ubuntu

mikhailov commented Thu Nov 27 12:40:00 UTC 2008:

I have found the article about downgrade Ruby 1.8.7 to 1.8.6. on Ubuntu 8.10 You can read this one at http://www.railsgeek.com

Raphael commented Sun Dec 28 21:34:55 UTC 2008:

Excellent article mate, installed perfectly.

Steve Cox commented Sat Jan 03 19:48:59 UTC 2009:

I love these tutorials.

Everything installed fine for me. I had previously installed Postfix using the email tutorials. So I did not install Postfix with Subversion per this article. Will that mess me up?

Thanks,

Steve

florida web design commented Sun Jan 04 22:08:48 UTC 2009:

That's what I'm talking about. I've used Media Temple for hosting, and they never give good tutorials on stuff like this. Thanks for the great work SliceHost.

pandian commented Tue Mar 03 14:09:05 UTC 2009:

I'm getting the following error

root@station11:/var/opt/sources/rubygems-1.2.0# sudo ruby setup.rb ./lib/rubygems/spec_fetcher.rb:1:in require': no such file to load -- zlib (LoadError) from ./lib/rubygems/spec_fetcher.rb:1 from ./lib/rubygems/source_index.rb:10:inrequire' from ./lib/rubygems/source_index.rb:10 from ./lib/rubygems.rb:767:in require' from ./lib/rubygems.rb:767 from setup.rb:22:inrequire' from setup.rb:22

Thanks in advance,

Bartee commented Tue Mar 10 00:25:42 UTC 2009:

RubyGem 1.3.1 is available

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

Jonathan commented Wed Apr 15 18:26:24 UTC 2009:

Hi, I'm having problems using the symlinks... I was able to successfully create them but they don't work! -- Please help! (I'm new to VPS/linux)

Lars Smit commented Sat Apr 18 10:32:51 UTC 2009:

RubyGems 1.3.2 is available: wget http://rubyforge.org/frs/download.php/55066/rubygems-1.3.2.tgz

Lars Smit commented Sat Apr 18 10:50:34 UTC 2009:

Install Git

  • sudo apt-get build-dep git-core
  • wget http://kernel.org/pub/software/scm/git/git-1.6.2.3.tar.gz replace with other version.
  • sudo tar -xvf git-1.6.2.3.tar.gz
  • cd git-1.6.2.3
  • sudo ./configure
  • sudo make
  • sudo make install

Paul commented Fri Aug 07 14:57:11 UTC 2009:

Hi all

don't forget to install rubygems-update after you install ruby gems

sudo gem install rubygems-update sudo gem update sudo gem update --system

tuyen dung commented Fri Aug 21 07:26:16 UTC 2009:

thanks you for write..It's very nice

Chase commented Sun Jan 31 19:15:40 UTC 2010:

I've done what has been suggested, but it appears as if Rails requires a bunch of other gems that weren't installed following this tutorial. I've had to manually install:

  • mongrel
  • rack 1.0.0
  • memcache-client
  • camping etc. Rails is now griping that it needs version 2.0.0 of ruby-openid..I feel like I may have missed a big step in the installation process that Rails requires..Any ideas?

Thanks!

Eric Boehs commented Fri Feb 12 04:15:10 UTC 2010:

I believe the only problem you'll have is installing rails. This is because actionpack requires version 1.0.x of rack and the latest version is 1.1.0 (the one you'll get if you try to install rack).

To fix it you simply need to run: sudo gem install rack --version=1.0.1

This is due to the fact that actionpack doesn't support rack 1.1.0 yet except in the beta version which is for Rails 3.0. The actionpack gem is kind of stuck between 2.3.5 rails and 3.0 beta rails.

mathiasbaert commented Wed Mar 03 11:27:38 UTC 2010:

On 9.10 karmic I couldn't do $ ruby -v until I made an alias $ alias ruby="ruby1.8" which fixed it, but I don't know whether that was the best solution

Evan commented Tue Mar 23 13:57:30 UTC 2010:

+1 to Eric Boehs fix for the rack problem. Perhaps the article should be updated to reflect this?

Santosh commented Wed Jun 02 07:39:45 UTC 2010:

Hi I am installing ruby gems on ubuntu 8.10 .. while installing i got the following error.

$wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz

Error : Name or service could not be resolved

Could you any one help on this ...

Thanks in advance.

Jered commented Wed Jun 02 14:49:35 UTC 2010:

Santosh, the problem might be that ruby gems has been updated since this article was written - the text of the article mentions going to their home page to get the latest release. You can go directly to the list of releases via this page. Then you can right-click the link to the latest release (1.3.7 while I write this), copy it, and use that link with wget to download the right file. Then in places where the article refers to version 1.2.0, just substitute 1.3.7.

If that isn't the problem (and it might not be, given the error message), there may be a DNS issue getting in the way. If you're running wget from your slice and it's giving that error, then your slice may not be using the right DNS servers (which could happen if you've made changes to /etc/resolv.conf, for example). If you still have that problem with the new version and can't find the DNS issue yourself, drop into SliceChat and someone there should be able to help you find the root of that problem.

david commented Fri Sep 17 17:14:53 UTC 2010:

Ican't install rails on centos 5.5 :(

gem install rails

ERROR: could not find rails locally or in a repository

Quang ba web commented Tue Oct 26 01:52:00 UTC 2010:

thanks your posted, i like it

rich commented Thu Mar 10 01:50:50 UTC 2011:

sorry, rails must hate me. nothing works. the rails website says 1.8.6 not supported, but i can't find how to install 1.8.7.

1.9 ruby fails with rails with some other Nil pointer nonesense.

is there a working Ubuntu/Hardy, 1-2-3 ruby/rails setup that works (django installs and works flawlessly)

rich commented Thu Mar 10 01:53:23 UTC 2011:

more info:

rich@noot:/usr/lib$ ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux] rich@noot:/usr/lib$ gem -v 1.6.1 rich@noot:/usr/lib$ sudo gem install rails Fetching: rails-3.0.5.gem (100%) Successfully installed rails-3.0.5 1 gem installed Installing ri documentation for rails-3.0.5... File not found: lib ERROR: While generating documentation for rails-3.0.5 ... MESSAGE: exit ... RDOC args: --ri --op /usr/lib/ruby/gems/1.9.0/doc/rails-3.0.5/ri lib --title rails-3.0.5 Documentation --quiet rich@noot:/usr/lib$ rail -v -bash: rail: command not found rich@noot:/usr/lib$ rails -v gem_prelude.rb:111:in push_gem_version_on_load_path': undefined method<=>' for nil:NilClass (NoMethodError) from gem_prelude.rb:11:in gem' from /usr/bin/rails:18:in<main>' rich@noot:/usr/lib$

Joel commented Sun Jul 13 04:52:17 UTC 2014:

It is not my first time to visit this site, i am browsing this web site dailly and obtain fastidious information from here everyday.

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)