Installing Rails on Ubuntu in Easy Steps
Introduction
This guide outlines a procedure for installing the following Rails environment:
- Ubuntu 11.10
- Ruby 1.92
- Rails 3.20
- Rubygems 1.8.15
- MySQL
- SQLite
- Git
Step 1: Update your operating system packages
The first thing we are going to do is get the latest updates for Ubuntu. The following two commands will download and install the latest Ubuntu updates.
sudo apt-get update sudo apt-get upgrade
Step 2: Install Ruby 1.9.2, build-essential, and git
Ubuntu provides several versions of Ruby. If you aren’t careful, you may end up installing older or even multiple versions. We want to install version 1.9.2 so we have the latest and greatest. For this, and other tasks ahead of us, we’ll also need build-essential as it has the developer tools that will be needed to compile various gems. Git is optional, but it doesn’t hurt to have a handy version control system at your disposal.
sudo apt-get install ruby1.9.2-full build-essential git-core
Step 3: Install RubyGems 1.8.15
Ubuntu is a few versions behind on their offical RubyGems package. So rather than using that we’ll use the RubyGems installation method here. You’ll download version 1.8.15 of RubyGems, unzip it, and then run the setup.rb program to install it.
wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.15.tgz tar -zxvf rubygems-1.8.15.tgz cd rubygems-1.8.15 sudo ruby setup.rb
Step 4: Update RubyGems
Once you have RubyGems installed, you want to double-check to make sure you have the latest version of the RubyGems software and then update all gems, if you have any installed.
sudo gem update --system sudo gem install rubygems-update sudo update_rubygems
Step 5: Install everything else
Now that you have RubyGems installed, it’s time to install Rails and the rest of the gang. One of the common issues I’ve run into when installing Rails is that I’d get compile errors when installing MySQL or SQLite. We’ll address that by installing the the right Ubuntu packages. I’ve also run into the occasional error when running commands to generate new models, controllers, etc. We’ll fix that by installing node.js as the JavaScript framework.
sudo gem install rails sudo apt-get install libsqlite3-dev sudo gem install sqlite3 sudo apt-get install nodejs sudo apt-get install mysql-server mysql-client sudo apt-get install libmysql-ruby libmysqlclient-dev sudo gem install mysql
Step 6: Test Drive
You should now have a working Ruby on Rails environment. To test it out, create a Rails application in your home directory as follows:
cd ~/ rails new app_of_the_century cd app_of_the_century rails generate model User
If you installation worked, Rails should create your application file/folder structure and generate a User model all without a single error.
Cut and Paste Version
Now that I’ve explained it step-by-step above, here’s a cut and paste version that should “just work” if you were to paste it into a terminal window.
sudo apt-get update sudo apt-get upgrade sudo apt-get install ruby1.9.2-full build-essential git-core wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.15.tgz tar -zxvf rubygems-1.8.15.tgz cd rubygems-1.8.15 sudo ruby setup.rb sudo gem update --system sudo gem install rubygems-update sudo update_rubygems sudo gem install rails sudo apt-get install libsqlite3-dev sudo gem install sqlite3 sudo apt-get install nodejs sudo apt-get install mysql-server mysql-client sudo apt-get install libmysql-ruby libmysqlclient-dev sudo gem install mysql
Source: http://www.brandedclever.com/the-perfect-rails-install-on-ubuntu-11-10