I’ll admit, I enjoy programming in Ruby on Rails. It’s the perfect fit for so many of my smaller projects where I need to build a small application and have it up and running quickly. However, sometimes it can be extremely frustrating to install a new system with the right versions of Rails, Ruby, MySQL, etc. Often times the distribution may have older packages or the gems are picky about what version of libraries are installed on the system. Well, if you run Ubuntu 11.10, this post is for you as it will outline a cut and paste set of commands to get you up and running with Ruby 1.92, Rails 3.20, Rubygems 1.8.15, MySQL and SQLite.
This guide outlines a procedure for installing the following Rails environment:
- Ubuntu 11.10
- Ruby 1.92
- Rails 3.20
- Rubygems 1.8.15
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
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
I certainly appreciate feedback so if you have other suggestions for a smoother Rails install on Ubuntu 11.10, add a comment to the post so that I can improve this post. Thanks in advance!