How To Install A Ruby 1.8 Stack on Ubuntu 8.10 From Scratch
Want 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 alternativelysudo
every line or just runsudo 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 (
http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
) and untar
,./configure
,make
andmake install
it by hand. You're on your own with that though.
Install RubyGems (from source)
curl http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz | 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 http://gems.github.com # 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 http://apt.brightbox.net hardy main" > /etc/apt/sources.list.d/brightbox.list wget -q -O - http://apt.brightbox.net/release.asc | 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 0.0.0.0/0 port 80 ufw allow to 0.0.0.0/0 port 22 # (or whichever port you use for ssh) ufw allow to 0.0.0.0/0 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).
February 27, 2009 at 4:36 am
*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.
February 27, 2009 at 4:43 am
But is there a danger that those might get updated to Ruby 1.9 at some point?
February 27, 2009 at 5:16 am
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.)
February 27, 2009 at 7:42 am
/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
http://hivelogic.com/articles/2005/11/using_usr_local
- Mike
February 27, 2009 at 7:56 am
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.
February 27, 2009 at 8:02 am
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.
February 27, 2009 at 8:04 am
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.
February 27, 2009 at 8:09 am
Found a fresh Intrepid image here. Running through instructions again to make sure it's all cool.
February 27, 2009 at 8:16 am
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!
February 27, 2009 at 9:59 am
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:
http://ubuntuforums.org/showthread.php?t=964978
Cheers
February 27, 2009 at 2:29 pm
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?
February 27, 2009 at 3:42 pm
Good article Peter.
Very nice collation of steps.
February 27, 2009 at 4:16 pm
@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.
February 27, 2009 at 5:40 pm
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.
February 27, 2009 at 5:59 pm
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).
February 27, 2009 at 7:48 pm
On Ubuntu, you can also use:
apt-get install ruby-full
To get all the various irb, rdoc, etc. in one fell swoop.
Pingback: Ruby-China
March 1, 2009 at 6:52 pm
Hi Peter,
we had a lot of issues with debian etch64
March 3, 2009 at 11:40 pm
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.
March 9, 2009 at 2:42 pm
Is there a reason why apt-get is used instead of aptitude?
March 9, 2009 at 2:48 pm
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!
March 9, 2009 at 8:30 pm
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
:)
optionally:
# echo "www-apache/passenger" >> /etc/portage/package.keywords
# emerge passenger
cheers for ubuntu! ;)
March 10, 2009 at 9:18 am
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.
March 11, 2009 at 7:01 pm
what about "apt-get install ruby-full" ?
March 17, 2009 at 9:33 pm
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