In a previous post, I discussed being able to install Rails 3.0 on Ubuntu 10.04. Today, we'll talk about all the steps necessary to install Rails 3.0 and get it running on Ubuntu 10.10.
Let's start off by installing the necessary packages from apt-get:
sudo apt-get install ruby ruby-dev libsqlite3-dev rubygems
You'll notice that there are some standard ruby packages, as well as the development package for sqlite3. Since sqlite is the default database for new Rails apps, and a really handy development tool since it doesn't require you to setup and maintain a database server on you machine, we'll include this right off the bat. The development files are needed to build the native Ruby extension through rubygems.
Since Ubuntu 10.10 comes with rubygems 1.3.7, it is able to install Rails 3.0 directly, so we won't have to do any trickery like in the last article. We can move right on to installing Rails:
sudo gem install rails
This should list a bunch of gems that are needed by rails as they're being installed, along with the associated documentation. The builder gem's documentation generation might fail with an error, but don't worry. It will still function.
There's one more thing that we have to do before using Rails. Rubygems on Ubuntu installs the executable gem files in /var/lib/gems/1.8/bin, which isn't in your system path by default. This means that we can't run gem executables from the command line until it's added to our path. For a temporary fix, you can do:
export PATH=$PATH:/var/lib/gems/1.8/bin
For a more permanent solution, create a .bashrc file in your home directory and add the previous command to it:
echo 'export PATH=$PATH:/var/lib/gems/1.8/bin' > ~/.bashrc
This assumes that you don't already have a .bashrc file (if it's a fresh install of Ubuntu, you won't). If you do, append the command to the end of the file.
Now we have full access to our gems. To create a new Rails project, go the directory you'd like to have it in and type 'rails generate <app name>', like:
rails generate myapp
Now you can configure the gems you'd like for your app in the Gemfile. For example, say you'd like to be able to use Haml as a markup language instead of the default erb, simply add
gem 'haml'
to Gemfile. Once you're done (and whenever you change this file), run:
bundle install
to automatically install all of the gems the app needs.
Now you're set. To run your app, run:
rails server
and enter http://0.0.0.0:3000 into your browser. You should be greeted by the friendly default Rails page.