Tuesday, September 18, 2007

Install Ruby On Rails on Fedora Core 7

Here are the steps to install Rails on a newly installed Fedora Core 7(FC7)

Step 1. Install Ruby

First we need to install Ruby related packages to the FC7.

If you've selected Ruby software package during the FC7 installation,
the installed version is already old. The installed version from
the FC7 is something like 1.8.6-2 and to a yum search showing that
there is already updates for 1.8.6.36-3. Thus it may be easier to
simply install Ruby manually(as shown below) after the FC7 install,
if you like to start with the latest of the software.

If you start with a freshly installed FC7 or this is the first time
you run yum on the system, you may need to run the following to
set up the yum:

$ yum grouplist

Next, you need to become the root:

$ su -

Install the following Ruby related packages that are essential for
anyone who likes to do development in Ruby:

# yum install ruby ruby-libs ruby-devel ruby-irb ruby-ri ruby-rdoc ruby-docs

Depends on type of the applications, here are few more useful packages:

# yum install eruby eruby-libs eruby-devel bsf ruby-tcltk


Step 1.1. Manually compile Ruby

If you like to compile the Ruby by hand, here are the steps, run as root:

# wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.6.tar.gz
# cd /tmp
# tar zxf ruby-1.8.6.tar.gz
# cd ruby-1.8.6
# ./configure --prefix=/usr
# make
# make test
# make install



Step 2. Install MySQL

If you haven't selected MySQL during FC7 installation, you need to
do it here:

# yum install mysql mysql-devel mysql-server

Step 3. Install RubyGems

It is recommended to install Rails from RubyGems. The latest
RubyGems as of this writing can be downloaded as follows:

# wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz

Move the downloaded file to, say, /opt, unzip and install:

# mv rubygems-0.9.4.tgz /opt/
# cd /opt
# tar xvfz rubygems-0.9.4.tgz
# cd rubygems-0.9.4
# ruby setup.rb

Step 4. Install Rails

# gem install rails --include-dependencies

Sometime the first install will fail with error such as
failed to find the package, just try run the install again.

Setup MySQL and Install Rails MySQL interface

Normally you will need a MySQL root user:

# service mysqld restart
# mysqladmin -u root password 'your-mysql-root-password'

Here is the standard install of MySQL interface library for Rails:

# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config


Step 5. Rails test

To verify the Rails installed correctly, simply create a skeleton
test in a local directory:

# rails test
# cd test
# ruby script/server

And then point your browser to:

http://localhost:3000/

If you see a Rails welcome page, then everything should have been
set up successfully.

3 comments:

Unknown said...

Great post Tom,

I was able to do this w/no problems. Thanks for helping a Fedora Core 7 newbie not trip over his own two feet.

Tom's Ville said...

Glad it helped. I learned alot from the others and am trying to contribute my part. I am working on few more pieces, so check back often when you have a chance.

David Tinoco said...

Hi Tom. I was able to do everything successfully until the gem install mysql step.

It gives me this error:

# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
Select which gem to install for your platform (i386-linux)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation
> 3
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

ruby extconf.rb install mysql -- --with-mysql-config=/usr/bin/mysql_config
checking for mysql_ssl_set()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-mysql-config


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out