Setting up Ubuntu 10.04 for Rails development
Every time a new version of Ubuntu is released use it as an opportunity to rebuild my development environment. It keeps things clean and fresh, and because I develop exclusively in virtual machines it’s easy and fast to do if you don’t have to do too much searching around.
Here’s what I want in my development environment on Ubuntu:
- RVM
- Apache and Passenger
- MySql and SQLite
- RubyMine development IDE
- Optional: Install UnixODBC and FreeTDS for SqlServer connectivity
Fairly standard setup, so let’s get started…
RVM
Before I install RVM, I always install Ruby 1.8.7. I’ve run into strange problems when I’ve installed RVM without first installing Ruby. I also like having a system Ruby installed. Typically this will be 1.8.7 simply because this is the version of Ruby that’s in the Ubuntu repositories.
sudo apt-get install irb libopenssl-ruby libreadline-ruby rdoc ri ruby ruby1.8 ruby-dev rake libopenssl-ruby git-core gitk git-gui libxml2 libxml2-dev libxslt1-dev libncurses5-dev libreadline5-dev
Then install RVM (see the RVM website for the latest instructions).
If RVM doesn’t already have Rubygems installed, here’s the manual recipe::
cd /usr/local/src sudo wget http://production.cf.rubygems.org/rubygems/rubygems-1.4.1.tgz sudo tar xzvf rubygems-1.4.1.tgz cd rubygems-1.4.1 sudo ruby setup.rb sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 1 sudo gem update --system
Before we move on, a couple of quick tweaks to two files in your home folder. First, add the following to the .gemrc file:
--- :backtrace: false :benchmark: false :bulk_threshold: 1000 :sources: - http://rubygems.org/ - http://gems.github.com :update_sources: true :verbose: true gem: --no-ri --no-rdoc
Then add this to the .gitconfig file:
[user]
name = [your name]
email = [your email]
[color]
ui = auto
Apache and Passenger
A basic installation of Apache and Passenger is easy:
sudo aptitude update sudo aptitude install apache2 sudo gem install passenger sudo passenger-install-apache2-module
The final command will check your system for dependencies. In my case the following command will sort that out:
sudo apt-get install build-essential sudo apt-get install libcurl4-openssl-dev libssl-dev zlib1g-dev apache2-prefork-dev libapr1-dev libaprutil1-dev
Rerun the passenger install command and it should succeed after all dependencies have been satisfied.
MySQL and SQLite
MySQL is essential, but I usually install SQLite too, because it’s simple and comes in handy sometimes.
sudo apt-get install libsqlite3-dev sqlite3 sqlite3-doc sudo gem install sqlite3-ruby sudo apt-get install libmysqlclient-dev mysql-server emma sudo gem install mysql
RubyMine development IDE
For RubyMine to run we need to install a java runtime. I’ve found the Sun JRE to be best, and this is how we get it:
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" sudo apt-get update sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts
Once that’s done, do a quick test to make sure everything is ok…
java -version
Now download and extract the RubyMine package and create a menu link to start RubyMine. You will need your license key when it starts.
Optional: Install UnixODBC and FreeTDS for SqlServer connectivity
This is optional because unless you need to connect to Microsoft SqlServer (I do for work!) you won’t need to do this. I’ve split these into separate commands because the sequence is very important – RUN EACH COMMAND SEPARATELY!
sudo apt-get install unixodbc sudo apt-get install unixodbc-dev sudo apt-get install freetds-dev sudo apt-get install freetds-bin sudo apt-get install tdsodbc sudo apt-get install libiodbc2
Install the Ruby ODBC binaries (we’ve found that this specific version works best for us):
cd /usr/local/src sudo wget http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9997.tar.gz sudo tar zvxf ruby-odbc-0.9997.tar.gz cd ruby-odbc-0.9997 sudo ruby extconf.rb --disable_dlopen make make install
Test the connection in irb:
require 'rubygems'
require 'dbi'
dbh = DBI.connect('dbi:ODBC:[dsn_name]', [username], [password])
You will need to manually configure the FreeTDS config files to get this working, but this is easily found on the web.