Howto install Rails 2.3, Ruby 1.9.1, MySQL 5.1 on Ubuntu Lucid 10.04 LTS or Ubuntu Maverick 10.10

NOTE:

This tutorial is out of date. Though Rails team said Rails 2.3 is nearly 100% compatible with Ruby19, there are many issues with third party gems. Thereby, it is not ideal to use Rails 2.3.x with Ruby19 in general. I’d highly recommend you to switch to Rails 3.x + Ruby 1.9.2 for best compatibility and performance.

I have written another tutorial on How to install Rails 3.x, Ruby 1.9.2. Link is here:

https://joneslee85.wordpress.com/2010/12/14/howto-install-rails-3-0-ruby-1-9-2-mysql-5-1-on-ubuntu-lucid-10-04-lts-or-ubuntu-maverick-10-10/

Prerequisites

Ubuntu repository contains Ruby 1.9.1 package however this package suffers few bugs that doesn’t run some Gem packages. So I would highly RECOMMEND you to compile for yourself a instance of Ruby 1.9.1 from source. To compile Ruby from source, you need to install compilers and libraries headers.

NOTE: This tutorial can be applied for Ubuntu Maverick 10.10. The only difference is installing libreadline6-dev instead of libreadline5-dev. But I highly recommend you guys to stay with Lucid 10.04 LTS for production server.

$ sudo apt-get -y install libc6-dev libssl-dev libmysql++-dev libsqlite3-dev make build-essential libssl-dev libreadline5-dev zlib1g-dev

Install Ruby 1.9.1 from source


$ cd /tmp
$ mkdir src
$ cd src
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p378.tar.bz2
$ tar xjvf ruby-1.9.1-p378.tar.bz2
$ cd ruby-1.9.1-p378
$ ./configure --prefix=/usr/local
$ sudo make && sudo make install

You can check if Ruby has been installed successfully by

$ ruby -v

and it should output

ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]

Should you see the “Happy new Ruby” returned, then your installation is ready to go

ruby -ropenssl -rzlib -rreadline -e "puts 'Happy new Ruby'"

Ruby 1.9 bundles RubyGem so you don’t have to install it

Update: Ruby 1.9.1-p429 and p430 released. You are NOT recommended to use this version. The reason is explained below. However if you like, you can install this patchset version:


$ cd /tmp
$ mkdir src
$ cd src
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p430.tar.bz2
$ tar xjvf ruby-1.9.1-p430.tar.bz2
$ cd ruby-1.9.1-p430
$ ./configure --prefix=/usr/local
$ sudo make && sudo make install

and make sure you replace any occurrences of 1.9.1-p378 with 1.9.1-p429 or p430 for next few steps.

For now, I stick with p378 because p429 and p430 suffer the force_encoding on frozen string in gem_prelude bug. This bug will give you error warning when you run


$ gem list
Error loading gem paths on load path in gem_prelude
can't modify frozen string
<internal:gem_prelude>:69:in `force_encoding'
<internal:gem_prelude>:69:in `set_home'
<internal:gem_prelude>:38:in `dir'
<internal:gem_prelude>:76:in `set_paths'
<internal:gem_prelude>:47:in `path'
<internal:gem_prelude>:286:in `push_all_highest_version_gems_on_load_path'
<internal:gem_prelude>:355:in `<compiled>'

Install SQLite3 and MySQL 5.1

$ sudo apt-get install mysql-server-5.1 sqlite3

Please make sure you set a password for MySQL server.

Install Rails and essential gems


$ sudo gem update --system
$ sudo gem install mysql rails rack rake mysql sqlite3-ruby
$ sudo gem install ruby-debug19 -- --with-ruby-include=./ruby-1.9.1-p378/

We can check if all gems are installed successfully

$ gem list

and it should list


actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activeresource (2.3.8)
activesupport (2.3.8)
rack (1.1.0)
rails (2.3.8)
rake (0.8.7)
mysql (2.8.1)
rubygems-update (1.3.5)
sqlite3-ruby (1.3.0)

Now you can generate your own Rails app. That’s all for now. See you in next tutorial.

About Jones Lee

Nothing much about me..

20 responses to “Howto install Rails 2.3, Ruby 1.9.1, MySQL 5.1 on Ubuntu Lucid 10.04 LTS or Ubuntu Maverick 10.10

  1. TNTNTNTN

    Darl, thanks for driving me everywhere to get barley flour today, even though we didnt manage to get it and banana muffins turn out to be a flop. Anyway, i just love the man in you. Hugss

  2. dynomite

    Thank you!!!

    Your post was helpful for newbies!

  3. kalypso

    Straight to the point, just what I am looking for

  4. kay

    thks. for that very good howto

  5. Nik

    Thanks a lot, this post was very helpful! I have been trying to get ruby 1.9.1 going for a couple days. Ubuntu annoys me sometimes. Why can’t I just use the packages in apt to make this work? (not directed at you)

    • Insy

      Just because packages must follow a fairly long process before being included in the stable branch.

    • Jones Lee

      I might take a very very very long time to get just few changes in the upstream into the Debian package version. Compiling from source is not a very elegant way but it does the job for you. I’ll see if I could manage to do a tutorial on how to create Debian package for Ruby 1.9.1.

  6. thx.. it’s work for me.. good job man. awesome..

  7. Ivan

    You are the man.
    Simple, objective and works!

    It has just a typing mistake:
    where … cd ruby-19.1-p378
    should … cd ruby-1.9.1-p378

    Thank you very much.

  8. JK

    Thank you much for the quick tutorial! It helped enormously…

  9. Insy

    Thank you very much, you saved me 🙂

  10. Sankar Adamesh

    FCUK! Thanks you so much for this tutorial, it’s sux how Ubuntu package lags behind the upstream but I guess not many people out there use pre-compiled binary ruby for their server, and as if they use Ubuntu LTS ….

  11. Angelee Pinzon

    Thanks a million! 😀

  12. hello
    thank you joneslee for this neat guide.
    it installed the latest rails by default (3.0.3), other version should be specified in the gem install line.
    can i copy your commands in my future rails help blog? i would like to retake the commands and explain them in french. (with a link to this blog).
    cheers

  13. Dana

    UGH, I was sure this was going to work, but when I ran ruby -v, I got:

    bash: /usr/bin/ruby: No such file or directory

    I had cut and pasted each line from the directions, and received no error messages! Thought for sure I had it working.

    Dana

  14. Dana

    I take that back! After I rebooted, ruby -v showed me it is indeed installed!!!! Thank you.

  15. Dana

    Was able to install Ruby, but not Rails & Gems. When I type the command, I get this error:

    /usr/local/lib/ruby/1.9.1/rubygems/spec_fetcher.rb:1:in `require’: no such file to load — zlib (LoadError)
    from /usr/local/lib/ruby/1.9.1/rubygems/spec_fetcher.rb:1:in `’
    from /usr/local/lib/ruby/1.9.1/rubygems/commands/update_command.rb:5:in `require’
    from /usr/local/lib/ruby/1.9.1/rubygems/commands/update_command.rb:5:in `’
    from /usr/local/lib/ruby/1.9.1/rubygems/command_manager.rb:140:in `require’
    from /usr/local/lib/ruby/1.9.1/rubygems/command_manager.rb:140:in `rescue in load_and_instantiate’
    from /usr/local/lib/ruby/1.9.1/rubygems/command_manager.rb:132:in `load_and_instantiate’
    from /usr/local/lib/ruby/1.9.1/rubygems/command_manager.rb:65:in `[]’
    from /usr/local/lib/ruby/1.9.1/rubygems/command_manager.rb:118:in `find_command’
    from /usr/local/lib/ruby/1.9.1/rubygems/command_manager.rb:104:in `process_args’
    from /usr/local/lib/ruby/1.9.1/rubygems/command_manager.rb:75:in `run’
    from /usr/local/lib/ruby/1.9.1/rubygems/gem_runner.rb:39:in `run’
    from /usr/local/bin/gem:24:in `’

    Can you tell me what I’m doing wrong??? Thanks!

    Dana

  16. Lan Chzou

    Thanks for post, I am very new to Rails and this helps me much with the installation. And also thanks for letting me know that this post is no longer up-to-date, now I am switched to Ruby 1.9.2 and Rails 3.x.

Leave a comment