Rails and MySQL on Ubuntu 10.10


Learning Ruby on Rails with MySQL on a Ubuntu machine is quick and easy with sqlite3 – the default for a Rails project. On a production project though you will probably need a database with a little bit more muscle. Let’s install MySQL and the needed connectors to get Rails to talk to it.


Make sure MySQL and all the necessary development packages are installed:

sudo apt-get install mysql-client-5.1 mysql-server-5.1 \
libmysqlclient16 libmysqlclient16-dev

Then get the needed RubyGems packages:

sudo gem install mysql

Then if you start a new project with MySQL:

rails new mysqltest -d mysql

And try to run the console:

cd mysqltest/
rails console

You will probably get an error like this:

Could not find gem 'mysql2 (>= 0, runtime)' 
      in any of the gem sources listed in your Gemfile.
Try running `bundle install`.

Easy enough… do as it says:

bundle install

You should see “Installing mysql2 () with native extensions” and hopefully no errors. Just edit your config/database.yml and you’re all set.

This entry was posted in Linux, Ruby on Rails. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">