Installing Ruby on Rails
July 18th, 2007
Introduction
Ruby on Rails is a agile web development framework written in Ruby. Ruby is a very easy to use and easy to learn language. The syntax is quite enjoyable to work with and it "just makes sense." I like to consider Ruby a no-intimidation programming language.
In this post I will go into the installation of the Ruby on Rails web application framework. Talk about best practices and creating your first rails application.
The Installation
I would recommend when setting up a Ruby on Rails server that you compile the packages from source. You are guaranteed to have a solid installation which in turn provides a solid foundation for your rails web applications.
Create Necessary Directories
mkdir -p /opt/local/src
cd /opt/local/src
Download Necessary Files
wget ftp://ftp.cwru.edu/pub/bash/readline-5.2.tar.gz
wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.6.tar.gz
Extract Downloaded Packages
tar xzf ruby-1.8.6.tar.gz
tar xzf readline-5.2.tar.gz
tar xzf rubygems-0.9.4.tgz
Setting Your Environment
echo 'PATH=/opt/local/bin:/opt/local/sbin:$PATH' >> ~/.bash_profile
The command above will automatically setup your PATH environment variable when you login. At this point run the following command to skip logging out and back in again.
. ~/.bash_profile
Installing Readline
cd readline-5.2
./configure
make
sudo make install
Installing Ruby
cd ../ruby-1.8.6
./configure --prefix=/opt/local --enable-pthread --with-readline-dir=/opt/local
make
sudo make install
Check Ruby Installation
bash $ ruby -v
ruby 1.8.6 (2006-08-25)
If it does not look like this then the ruby installation either failed or your path is not correct
Installing RubyGems
cd ../rubygems-0.9.4
ruby setup.rb
Installing Ruby on Rails
sudo gem install rails -- --include dependencies
If this step above fails just press the up arrow and run it again. It will work, there is some sort of bug in rubygems that causes this to fail on the first run.
Creating Your First Application
mkdir -p /var/www
cd /var/www
rails firstapp
cd firstapp
./script/generate controller hello index
echo "Hello World" > app/views/hello/index.rhtml
./script/server
Now open a web browser and navigate to the server's IP address, if it is on the local machine use 127.0.0.1:3000. This will display the web application that you just created. Now type the following into the URL.
http://127.0.0.1:3000/hello/
Now the Hello World web application should appear in your web browser.
Where To Go From Here
Now that you have a fully working development environment setup on any operating system you are all set to either start developing in Rails or upgrading this machines purpose to be a production Ruby on Rails server.
Leave a Reply