Technetra

How to Setup Ruby on Rails for Fedora 10 and 11

Nilayan Sharma,  April 22nd, 2009 at 4:15 am

In this how-to, we will step through the process of setting up a Ruby on Rails development environment on Fedora 10 and Fedora 11 Beta. To follow along, just cut and paste the commands in a terminal window.

The instructions in this how-to are based on a fresh installation of Fedora 10 (32-bit/64-bit) and Fedora 11 Beta (32-bit only). During the installation process, we selected the “Software Development” package which includes the tools (e.g., gcc, svn, git, make) and libraries needed for building and compiling software.

1. Development tools

First, let’s check to see if you have the basic set of development tools — gcc, make and git. Although these tools are installed as part of the “Software Development” package, you can check if they are on your system by running ‘which gcc make git‘ at the command line.

[root@fc10 ~]# which gcc make git
/usr/lib/ccache/gcc
/usr/bin/make
/usr/bin/git

Note: On Fedora 10 64-bit systems, the full path to gcc is /usr/bin/gcc.

If the tools are not on your system, then you can install them by running the following command.

[root@fc10 ~]# yum install gcc make git

2. Databases: MySQL, SQLite

A typical Rails application is backed by a relational database. We will install both MySQL (v5.0.77) and SQLite (v3.5.9) for our environment. Recent versions of Rails default to using SQLite. If set up on your system, however, MySQL is also easily used.

[root@fc10 ~]# yum install mysql-server mysql-libs mysql-devel
[root@fc10 ~]# yum install sqlite sqlite-devel

3. Ruby language

Next, we’ll install the core packages for Ruby (v1.8.6.287). We’ll also need the two packages ruby-mysql and ruby-sqlite3 for database access from Ruby programs.

[root@fc10 ~]# yum install ruby ruby-devel ruby-libs ruby-mode ruby-rdoc ruby-irb ruby-ri ruby-docs ruby-mysql ruby-sqlite3

4. RubyGems

RubyGems is the packaging system for Ruby applications and libraries. Each application or library is known as a gem. By default, gems are installed in ‘/usr/lib/ruby/gems‘ (’/usr/lib64/ruby/gems‘ on Fedora 10 64-bit systems). RubyGems lets you easily install and remove gems using the gem command. We’ll install the latest version of RubyGems (v1.3.2).

[root@fc10 ~]# wget -q http://rubyforge.org/frs/download.php/55066/rubygems-1.3.2.tgz
[root@fc10 ~]# tar xzf rubygems-1.3.2.tgz
[root@fc10 ~]# cd rubygems-1.3.2
[root@fc10 rubygems-1.3.2]# ruby setup.rb

5. Rails

Now that we have a sparkling RubyGems toolset, the first gem we are going to install is the Rails (v2.3.2) web application framework. An advantage of installing Rails using the gem command is that package dependencies are resolved automatically.

[root@fc10 ~]# gem install rails

6. Mongrel

Rails provides WEBrick, a simple HTTP server that can be used to test applications during development. However, WEBrick is not suited for production environments. Mongrel is a web server commonly used for Ruby web applications. A typical configuration consists of a Mongrel cluster (several Mongrel instances) behind a front-end Apache web server. We’ll install Mongrel 1.1.5.

[root@fc10 ~]# gem install mongrel mongrel_cluster

7. JSON

JSON (JavaScript Object Notation) is a lightweight data interchange format - a sort of “low-fat” alternative to XML. We’ll install the Ruby implementation of the JSON specification, json (v1.1.4). This allows the conversion of Ruby objects to JavaScript objects for use by clients running on the browser.

[root@fc10 ~]# gem install json

8. SQLite3 Ruby

The sqlite3-ruby gem provides Ruby bindings for SQLite3 databases, the default database system for recent Rails environments. We’ll install version 1.2.4.

[root@fc10 ~]# gem install sqlite3-ruby

9. Ruby MySQL

The mysql gem provides a client-side MySQL API for Ruby programs. Before we install the gem, we’ll need to create symbolic links in ‘/usr/lib‘ (’/usr/lib64‘ on Fedora 10 64-bit systems) to point to the MySQL client libraries installed in ‘/usr/lib/mysql‘ (’/usr/lib64/mysql‘ on Fedora 10 64-bit systems).

Fedora 10

[root@fc10 ~]# cd /usr/lib
[root@fc10 lib]# ln -s mysql/libmysqlclient.so
[root@fc10 lib]# ln -s mysql/libmysqlclient.so.15
[root@fc10 lib]# ln -s mysql/libmysqlclient_r.so
[root@fc10 lib]# ln -s mysql/libmysqlclient_r.so.15

Note: On Fedora 10 64-bit systems, the symbolic links should be created in ‘/usr/lib64‘.

Fedora 11 Beta

[root@fc11 ~]# cd /usr/lib
[root@fc11 lib]# ln -s mysql/libmysqlclient.so
[root@fc11 lib]# ln -s mysql/libmysqlclient.so.16
[root@fc11 lib]# ln -s mysql/libmysqlclient_r.so
[root@fc11 lib]# ln -s mysql/libmysqlclient_r.so.16

Or for the brave, just run this on either Fedora 10 or 11:

[root@fc10 ~]# cd /usr/lib
[root@fc10 lib]# for f in mysql/libmysql*.so mysql/libmysql*.so.1[56]; do ln -s $f; done

Note: On Fedora 10 64-bit systems, the symbolic links should be created in ‘/usr/lib64‘.

Now, we are ready to install the Ruby MySQL (v2.7) gem by running the following command.

[root@fc10 ~]# gem install mysql

10. Riding the Rails

Now it’s time to test your installation. A great way to do this is to follow the simple tutorial at ‘Getting Started with Rails‘. Build the blogging application described there twice: once for SQLite3 and then again for MySQL. If the application can be built without errors, your database environments are set up properly.

That’s it! Your shiny new environment is waiting for you to build your next Rails application on Fedora using SQLite and MySQL.

Copyright © 2009 Technetra. This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Discovering Web Access Latencies Using Bash Co-Processing Article Index Tutorial: Comparing Yahoo! and Google Maps APIs Side-by-Side

Comments

6 Responses to “How to Setup Ruby on Rails for Fedora 10 and 11”

  1. May 22nd, 2009 at 8:00 am (Comment)
    Anonymous User Says:

    Nice tutorial! Great job!

  2. June 12th, 2009 at 7:32 pm (Comment)
    vf Says:

    Fantastic tutorial. I love it when supersmart people are able to dumb stuff down for us smart people. Thanks for stepping me through this. Ruby on Rails is fun - but for us tweakers out there - getting things set up seems like 1000 steps. Your tutorial was crisp, clean, easy to read, logical, and … it worked. Thank you very much.

  3. June 12th, 2009 at 7:44 pm (Comment)
    vf Says:

    Two notes:
    1 - For unix morons like me … down forget to bounce back to the root directory as you move through this tutorial. i.e. after setting up ruby gems I instantly installed rails without taking note that I was still in the rubygems directory

    2 - I had to ‘yum wget’ because the ‘wget’ command was not found by default on a fresh install of Fedora 11.

  4. September 26th, 2009 at 8:56 am (Comment)
    Tom Atlas Says:

    Great post! Helped a ton!

  5. September 29th, 2009 at 4:09 pm (Comment)
    Dewang Says:

    Great guide. Thanks a ton!

  6. October 7th, 2009 at 3:32 am (Comment)
    Mukesh Says:

    After you install mysql, set its root password
    $ mysqladmin -u root password NEWPASSWORD

Add a comment