Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

How To Install A Ruby 1.8 Stack on Ubuntu 8.10 From Scratch

By Peter Cooper / February 27, 2009

ubuntu.pngWant to install Ruby, RubyGems, and a collection of common gems on Ubuntu 8.10 (Intrepid Ibex) in just a few minutes? Here's the skinny.

If you want, you could use something like Passenger-Stack to do the legwork for you, but I prefer doing manual installations so I know the full score. There are several "how to install Ruby on Ubuntu Intrepid" guides out there but none of them got it totally right for me. I've just used these instructions twice in a row so I know they work. Another bonus is you get ImageMagick and rmagick installed which some people get really frustrated with..

Note: These instructions assume you're running as root for convenience. You can alternatively sudo every line or just run sudo bash until you're done.

Install the system level basics

apt-get update
apt-get -y install build-essential zlib1g zlib1g-dev libxml2 libxml2-dev libxslt-dev sqlite3 libsqlite3-dev locate git-core
apt-get -y install curl wget

Install ImageMagick (for rmagick)

apt-get -y install libmagick9-dev

Install Ruby 1.8 (MRI)

apt-get -y install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby
ln -s /usr/bin/ruby1.8 /usr/bin/ruby
ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc
ln -s /usr/bin/irb1.8 /usr/bin/irb
ln -s /usr/bin/ri1.8 /usr/bin/ri

Note: Some advise not to use the packaged version of Ruby on Ubuntu due to its performance. I'm not worried about this. If you are, replace this section with a download of the Ruby source code ( and untar, ./configure, make and make install it by hand. You're on your own with that though.

Install RubyGems (from source)

curl | tar -xzv
cd rubygems-1.3.5 && ruby setup.rb install
cd .. && rm -rf rubygems-1.3.5
ln -s /usr/bin/gem1.8 /usr/local/bin/gem
gem sources -a # add Github as a gem source, you won't regret it

Install a set of starter Ruby gems

gem install rake nokogiri hpricot builder cheat daemons json uuid rmagick sqlite3-ruby fastthread rack

What next?

By this point you now have Ruby installed with RubyGems, a collection of gems (including rmagick) and you can branch off where you want. If you want to develop a Sinatra app, install the sinatra gem and you're away. If you want to install Rails, gem install rails. And so forth.

If you want to install Apache with Passenger for hosting your apps, however, read on..

Optional: Install Apache and Passenger

echo "deb hardy main" > /etc/apt/sources.list.d/brightbox.list
wget -q -O - | apt-key add -
apt-get update
apt-get -y install libapache2-mod-passenger

Note: Brightbox's Passenger package is officially for Ubuntu 8.04 (Hardy) but it works fine on Intrepid in my experience.

If you need PHP5 as well:

apt-get -y install php5 libapache2-mod-php5 php5-mysql
/etc/init.d/apache2 restart

Optional: Need a very, very basic firewall?

apt-get -y install ufw
ufw allow to port 80
ufw allow to port 22 # (or whichever port you use for ssh)
ufw allow to port 25 # (if you need mail in)
ufw enable

Note: You're installing the firewall, not me, so don't complain if you get locked out because of the firewall or something :) Ensure you have the correct ports and/or a console access to your server just in case (such as Linode supplies).


  1. Kevin Bullock says:

    *ACK* *COUGH* Creating symlinks by hand in /usr/bin is a bad idea. Rather than typing all those extra 1.8's, why not just do this?

    apt-get -y install ruby-dev ruby ri rdoc irb libreadline-ruby libopenssl-ruby

    Then the symlinks are created and managed automatically.

  2. Peter Cooper says:

    But is there a danger that those might get updated to Ruby 1.9 at some point?

  3. Peter Cooper says:

    Also, if you could elaborate on why it's a bad idea, that'd be awesome. I'd like this to be a good guide. I've used symlinks for this sort of thing for years with no issues but am always happy to learn!

    (If it's the "when you upgrade, those symlinks might get overwritten" reason, then I'm not too concerned. If one's performing major upgrades, one should be testing one's results.)

  4. Mike Bailey says:

    /usr/local is where you put packages that weren't installed using your systems package installer. That way they won't get clobbered when you do a system update.

    If you install system packages then don't link them into /usr/local.
    It's unneccessary and not in keeping with the Filesystem Hierarchy Standard (FHS). Your system should look for executables in /usr/local first and then look in the locations where the system (linux, osx, etc) installs code. This is controlled by you PATH environment variable.

    e.g. /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    Dan Benjamin wrote a good piece explaining /usr/local

    - Mike

  5. Seth Chandler says:

    I don't mean to start an editor flame-war here, but it seems like nano is completely unnecessary in this setup. I'm not trying to take things off-topic, but the setup above (with the exception of the offending line) is completely editor neutral.

  6. Peter Cooper says:

    Thanks for all of your suggestions. I have made some tweaks to the instructions. The only downside to this is that I can't say hand-on-heart that they will definitely work anymore. However, I don't believe these changes should have had any effect since, yes, /usr/bin is in the path by default anyway.

  7. Peter Cooper says:

    Hmm.. it seems like /usr/bin/ruby might already be created actually. Ha, I'm totally screwed now unless I start fresh with another VM *groan* I'll leave it and cross my fingers for now.

  8. Peter Cooper says:

    Found a fresh Intrepid image here. Running through instructions again to make sure it's all cool.

  9. Peter Cooper says:

    Nope, it appears /usr/bin/ruby doesn't exist. It seems Brightbox's libapache2-mod-passenger is making the "ruby" package a dependency.. eugh. Perhaps going to the "ruby" packages would be a goer then. Unsure.

    In any case, for anyone who's reading, the way presented above does work - it just might not be the 100% perfect way ;-) More reviews welcomed. The more peer reviewed it is, the better!

  10. Nazar says:

    Hi Peter.

    I am not sure if this is relevant to your article but one issue I had with Ubuntu 8.10 is that it tried to install Ruby 1.8.7.x, whereas I was more comfortable with Ruby 1.8.6.x.

    The workaround is detailed in this post:


  11. rtgrtgrtg says:

    I think installing ruby is not a rocket science, what really drives me crazy is RMagick. Which is used frequently by many of our customer projects, for *X systems most of the guides are not working and you always have to tweak the buld processes and reslove dependencies. Are there any good ressources on this, or is there another lib which provides same features, performacne and qulity as libmagick/RMagick?

  12. chetan says:

    Good article Peter.
    Very nice collation of steps.

  13. Peter Cooper says:

    @rtgrtgrtg: What distribution / OS? On Ubuntu it's easy as shown above. Just install the libmagick9-dev package and then install the rmagick gem. It's also pretty easy on OS X as far as I recall using DarwinPorts though I can't remember the exact line for that. On CentOS it's not too bad either, there are a few yum packages that will install ImageMagick in the right way.

  14. Kevin Bullock says:

    Re: #2 and #3, to elaborate:

    It's best to let the package manager handle all of /usr/bin by itself, since yes, the symlinks could very well get overwritten, or worse: they could cause a fatal conflict causing dpkg to bail if you ever do try to install the 'ruby' package. (Not sure in this specific case what'd happen, but similar cases have bit me many times.)

    There's no danger of 'ruby', 'irb', 'ri' etc. bumping up to depend on 1.9, except on a full-distro version upgrade (i.e. when jinky jellyfish comes out). And as you said yourself, "If one's performing major upgrades, one should be testing one's results."

    Of course, either way, if you're testing on upgrades, you'll be okay. I find it generally less painful to stay well out of the way of dpkg's intents.

  15. Peter Cooper says:

    Thanks for the clarifications, Kevin.

    Brightbox's package does seem to make the "ruby" package install, yet, as far as I can tell, little happens. The symlink /usr/bin/ruby1.8 -> /usr/bin/ruby is maintained, so either that's how the ruby package does it, or it doesn't want to overwrite.

    I'm going to leave the instructions as-is for now, as I'm happy with a messier pragmatic approach over a formal one, but hopefully these comments will be of great help to people who do want to do things in slightly different ways (such as installing the ruby packages, as you suggest).

  16. Sean Bowman says:

    On Ubuntu, you can also use:

    apt-get install ruby-full

    To get all the various irb, rdoc, etc. in one fell swoop.

  17. Pingback: Ruby-China

  18. rtgrtgrtg says:

    Hi Peter,

    we had a lot of issues with debian etch64

  19. Phil says:

    It's a good idea to let Debian's update-alternatives system handle the links between ruby1.8 and ruby etc. That's the package-manager-friendly way, and it's no more difficult than doing the symlinks manually.

  20. Chris says:

    Is there a reason why apt-get is used instead of aptitude?

  21. Peter Cooper says:

    Since apt-get added autoremove support, I don't think there's a significant difference between them (for just installing and removing packages without needing the snazzy menus, search, etc). Might be wrong though!

  22. Fred says:

    jezzz.. how many commands?!?!

    in gentoo 2 commands would be enough...

    # emerge rubygems rmagick

    # gem install rails rake nokogiri hpricot builder cheat daemons json uuid sqlite3-ruby fastthread rack



    # echo "www-apache/passenger" >> /etc/portage/package.keywords
    # emerge passenger

    cheers for ubuntu! ;)

  23. Phil says:

    Ohh, I don't care about what should/shouldn't be done.
    To say that you've made this excellent Ruby installation a breeze
    is a must.

    Thanks you so much Peter.

  24. fred says:

    what about "apt-get install ruby-full" ?

  25. Matthew says:

    Awesome guide. Got me 99% of the way there.

    Just a quick note: I decided to go down the ruby compilation route (have has bad experiences with apt-get + ruby) I kept getting Zlib file not found errors when trying to install gems. The following steps fixed that:

    # cd /path/to/src/ruby-1.8.x-xx/ext/zlib/
    # ruby extconf.rb
    # make && make install

Other Posts to Enjoy

Twitter Mentions