Howto install rails 2.3 and ruby 1.9 on ubuntu for mysql and sqlite3

Prerequisite
As a prerequisite you will need to install the following packages,these packages are build tools and libraries you will need for compilation process.

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

Installing Ruby 1.9.1

cd ~
mkdir src
cd src/
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.gz
tar xzvf ruby-1.9.1-p0.tar.gz
cd ruby-1.9.1-p0/
wget http://redmine.ruby-lang.org/attachments/download/237
patch -p1 < 237
./configure --prefix=/usr/local --with-openssl-dir=/usr --with-readline-dir=/usr --with-zlib-dir=/usr 
sudo make && sudo make install

To make sure form your ruby version use the following command line.

ruby -v

The output should be something like this

ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]

If this command only returns “Happy new Ruby” please feel comfortable, your instllation is going fine.

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

Ruby 1.9 bundles rubygems so there is no need to install it.

Installing mysql-ruby adaptor

cd ~/src
wget http://rubyforge.org/frs/download.php/51087/mysql-ruby-2.8.1.tar.gz
tar xzvf mysql-ruby-2.8.1.tar.gz
cd mysql-ruby-2.8.1
sudo ruby extconf.rb
make
sudo make install

Installing rails and other stuff

sudo gem install rails rake rack sqlite3-ruby

To make sure that all packages are successfully installed use the following command line

gem list

The output should be something like this

actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activeresource (2.3.2)
activesupport (2.3.2)
rack (0.9.1)
rails (2.3.2)
rake (0.8.4)
sqlite3-ruby (1.2.4)

Now you can create and run a new rails application working on ruby 1.9 “.

For mysql database

rails yourapp --database=mysql

For sqlite3

rails yourapp
rubyonrails 2.3

rubyonrails 2.3

With best wishes for fast performance.


30 Responses to “Howto install rails 2.3 and ruby 1.9 on ubuntu for mysql and sqlite3”

  • Chris Says:

    rails give mysql error after the installation completes

  • Amer Says:

    What exactly is the error message? Maybe I can help you.

  • Chris Says:

    Status: 500 Internal Server Error
    no such file to load — mysql

  • Chris Says:

    The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.

  • Chris Says:

    I dont even have rails 2.2 installed

  • Chris Says:

    I will use sqlite for now until that error is resolved.

  • Louis Muloka Says:

    This was helpful. Thanks!

  • Chris Says:

    It all install fine but have mysql problem. When i try to migrate i get: Packets out of order: 0 error message?

  • Amer Says:

    It sounds like a compatibility problem, are you using Mysql 5.1 or later? if yes try it again with mysql 5.0 but check your database.yml configurations first.

  • Nilakanta Says:

    Just add “sudo make install” as the last step of “Installing mysql-ruby adaptor”.
    Also don’t forget to install mysql by running command “sudo apt-get install mysql-server mysql-client libmysqlclient15-dev”.

  • Shaun Says:

    Thanks for the great post! It really helped me out a lot. I just installed ubuntu 9.04 and was trying to run ruby 1.9 but had installed both version 1.9 and 1.8.7.

    So typical of multi ruby versions there were many issues and headaches. So I googled and then got your blog. Copy-and-paste and then I’ve got a fully functional ruby1.9 environment :)

  • chris Says:

    Thanks for the help great good post

  • Amer Says:

    I’m glad to hear that.

  • David Beckwith Says:

    There is a mistake in the post. After the line:
    sudo ruby extconf.rb

    You have to type in:
    make
    sudo make install

    Then it will work.

  • Amer Says:

    Nilakanta and David Thanks guys for your correction.

  • Jones Lee Says:

    Hi, I installed ruby-1.9.1-p129 and mysql gem doesn’t install correctly. The extconf.rb does not generate makefile, do you know how to fix it?

  • andi Says:

    I followed your instructions and managed to install everything. But there are still some issues (regarding the mysql-ruby adaptor, I think).
    For example, running `rake db:migrate` works fine, but when I run my rails app I get the following error:

    undefined method `init’ for Mysql:Class

    /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:73:in `mysql_connection’

    Any ideas on what might be causing this?
    Thanks.

    (This is the production environment, running Ubuntu and the app runs fine – on ruby1.9.1 / rails2.3.2 / OS X – on my development machine)

  • Julian Burgess Says:

    How do I uninstall it or set the default back to Ruby 1.8? Thanks

  • Rajeswar Reddy Says:

    Please let me know, how to install rails 2.3 and ruby 1.9 on ubuntu for mysql and sqlite3 on “Windows”

  • Rajeswar Reddy Says:

    Hi All,

    I am installed Ruby-1.9.1 and gems rails,rake ,ack,sqlite3-ruby on my windows machine, below gem list is available on my machine.

    *** LOCAL GEMS ***

    actionmailer (2.3.3)
    actionpack (2.3.3)
    activerecord (2.3.3)
    activeresource (2.3.3)
    activesupport (2.3.3)
    dbi (0.4.1)
    deprecated (2.0.1)
    needle (1.3.0)
    net-scp (1.0.2)
    net-sftp (2.0.2)
    net-ssh (2.0.11)
    rack (1.0.0)
    rails (2.3.3)
    rake (0.8.7)
    ruby-oci8 (2.0.2)
    sqlite3-ruby (1.2.5)

    But I am unable to install (no idea how to install) the “mysql-ruby adaptor” on my “windows” machine, please let me know the installation process.

  • Amer Says:

    Sorry my friend but I don’t use Windows a lot, specially for development, but I’ll highly recommend to you Ubuntu and Netbeans for your development environment, believe me you will feel the big difference.

  • Amer Says:

    Julian I’m sorry to be late that much, I think the easiest way is to compile Ruby 1.8 and reinstall it.

  • Rajeswar Reddy Says:

    Thanks Amer..!

    Please if anyone knows about installation of “mysql-ruby adaptor” on windows let me know.

  • Fitz Says:

    Thanks, this is exactly what I needed, it’s a little out of date but now I have ruby/rails all up to date and working. Good work!

    root@———-:~# gem list

    *** LOCAL GEMS ***

    actionmailer (2.3.4)
    actionpack (2.3.4)
    activerecord (2.3.4)
    activeresource (2.3.4)
    activesupport (2.3.4)
    rack (1.0.0)
    rails (2.3.4)
    rake (0.8.7)
    sqlite3-ruby (1.2.5)
    root@——-:~# ruby -v
    ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux]

  • Bilal Aslam Says:

    Thanks a lot :) I wonder why ubuntu doesnt regularly update their packages with ruby stuff :(

    [~]$ gem list (09-12 23:32)

    *** LOCAL GEMS ***

    actionmailer (2.3.4)
    actionpack (2.3.4)
    activerecord (2.3.4)
    activeresource (2.3.4)
    activesupport (2.3.4)
    rack (1.0.0)
    rails (2.3.4)
    rake (0.8.7)
    sqlite3-ruby (1.2.5)

  • Javix Says:

    Amer, I went up to ’sudo make && sudo make install’ and I got at the very end the error:

    gcc -O2 -g -Wall -Wno-parentheses -I. -I.ext/include/i686-linux -I./include -I. -DRUBY_EXPORT -o cont.o -c cont.c
    cont.c:90:6: error: #elif with no expression
    cont.c:270:6: error: #elif with no expression
    cont.c:317:6: error: #elif with no expression
    make: *** [cont.o] Error 1
    serge@ubuntu:~/src/ruby-1.9.1-p0$ ruby -v
    The program ‘ruby’ is currently not installed. You can install it by typing:
    sudo apt-get install ruby
    ruby: command not found

    Any idea how to resolve it? I’m on Ubuntu 9.10. Thank you.

  • Javix Says:

    I’m on Ubuntu 9.10 ‘KArmic Koala’ and I folllowed your instrtuctions to install just ruby 1.9.1. After I did

    serge@ubuntu:~/src/ruby-1.9.1-p0$ cd ~
    serge@ubuntu:~$ ruby -v
    The program ‘ruby’ is currently not installed. You can install it by typing:
    sudo apt-get install ruby
    ruby: command not found
    serge@ubuntu:~$

    Any idea Amer?

  • Hardik Joshi Says:

    hello…
    this post helped me a lot to install rails in ubuntu..
    but m getting error while installing some gems..like unicode and slim_scrooge

    make: *** [callsite_hash.o] Error 1

    Plz guide me how to solve it???

  • Ben Lin Says:

    My problem is similar to Javix’s.

    After I typed ’sudo make && sudo make install’ and I got at the very end the error:

    gcc -O2 -g -Wall -Wno-parentheses -I. -I.ext/include/x86_64-linux -I./include -I. -DRUBY_EXPORT -o cont.o -c cont.c
    cont.c:90:6: error: #elif with no expression
    cont.c:270:6: error: #elif with no expression
    cont.c:317:6: error: #elif with no expression
    make: *** [cont.o] Error 1

    Could you give us any hint to solve this issue?

  • Amer Says:

    Hi Ben,
    Are you sure you have the right versions? anyway try to run rails 3 on Ruby 1.9 it’s still beta but for sure it’s more compatible than this one.
    http://weblog.rubyonrails.org/2010/2/5/rails-3-0-beta-release
    good luck.

Leave a Reply