This post was originally published at http://www.the-tech-tutorial.com/?p=1868
Ruby Rails is a Web application framework created in 2004 intended as a rapid development web framework that runs the Ruby programing language. The latest version of the Ruby is ‘Ruby 1.9.2‘ and was realised in August 2011, it brings many new features and bug fixeses. The most signifiant changes are Block local variables, An additional lambda syntax, Per-string character encodings are supported and a new New socket API (IPv6 support). You can find a great walkthrough of all the new features at Ruby Inside. coinciding with the release of Ruby 1.9 is the Rails 3.1 framework which requires Ruby 1.8.7 or higher. RubyonRails 3.1 brings many new features, most notably: jQuery as default, HTTP Streaming, a new assets pipeline powered by Sprockets 2.0. So this is all good stuff and I’m sure you want to be working with the latest version of Ruby and RubyonRails, especially if you setting up a new server.
Well if your using Ubuntu you can setupRuby and RubyonRails quickly using the supplied repository’s, a good tutorial for this can be found here. However this is not recommended as the Ubuntu repositories are often out of date and if you install ruby orrails via the repository’s it can be pain toupgrade. So in this guide we are going to go through installing RVM (this allows you toinstall, change and upgrade the installedRuby version), Ruby 1.9.2 and Rails 3.1. This Guide has been tested on Ubuntu 11.10 however it should work on all versions of Ubuntu later then Ubuntu 9.04.
First of all you’ll need to install some packages that Ruby, RVM and RubyOnRailswill require later, the easiest way to do this is using the repositories so go to your terminal and type:
sudo apt-get update
sudo apt-get install build-essential git-core curl libmysqlclient16-dev nodejs
Now let’s install the latest version of RVM using curl:
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
Now you’ll need to ask RVM if it needs any more programs and if so you’ll need to install them to do this type:
Two things could happen here if you see the following message saying you need to install ‘rvm‘, ignore this it and restart your terminal, this should fix the problem.
The program 'rvm' is currently not installed. You can install it by typing:
sudo apt-get install ruby-rvm
You should see something that looks like this after you restart your terminal:
This tells you which packages you need to install using apt-get, just copy and paste the apt-get section under “# ForRuby” and run using the sudo command, this should look something like this:
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
Once you have installed all these packages its time to install Ruby 1.9.2 herself. The following command will installRuby 1.9.2 using the rmv package. However this can take a few minutes (15 in my case) to install so I recommend getting a drink, or my favourite, a pizza .
rvm install 1.9.2
Once ruby is installed you should set Ruby 1.9.2 as your default Ruby version, to do this enter:
rvm --default use 1.9.2
You can test that Ruby is installed correctly and running at version 1.9.2 by typing
This should output something like “ruby 1.9.2p290..” showing you that version 1.9.2p290 is installed and is now the defaultRuby version.
The nice thing about RVM is you can use it to install any version of Ruby and switch between the versions your have installed, to do this just enter “rvm install [Version Number]” then “rvm –default use [Version Number”, you can then use “rvm –default use” to change to any installed version.
Now that you have the latest version of ruby installed I’m sure you want to get the latest version of Rails installed, at the time of writing this tutorial that’s Rails 3.1. To installRails we can use GEM which is installed along with RVM and Ruby, to install the latest version of Rails just type, (this can take also take a while):
gem install rails
And that’s it you have now installed RVM, Ruby 1.9.2 and Rails 3.1 on Ubuntu 11.10 configured to use sqlite3, you can now setup your new Rails package with
rails new [project name]
Just as a final note, If you want to use MySQL instead of sqlite3 you’ll need to enter the following
sudo apt-get install mysql-server
gem install mysql2
rails new [project name] -d mysql