Method 1 – railsready
If you don't want to do everything manually, you can use the railsready script, which will install for you:
- An updated system (Linux only)
- Ruby 1.9.3 latest patch level (installed to /usr/local/bin/ruby) or RVM running 1.9.3 latest patch level
- Imagemagick
- libs needed to run Rails (sqlite, mysql, etc)
- Bundler, Passenger, and Rails gems
- Git
Just enter the following:
wget --no-check-certificate https://raw.github.com/joshfng/railsready/master/railsready.sh && bash railsready.sh
… and you're done.
Method 2 – Manual install and RVM
As @slotishtype has mentioned, do yourself a favor and install Ruby over RVM. It manages Ruby versions better, you don't need to sudo anything, and you'll be able to get more recent versions of Ruby.
How to install RVM
You need git for that, so if you don't have it, install it with sudo apt-get install git before. Also, @nixterminus has a blog post on that subject, written for Ubuntu 11.04. It features some other dependencies that you might need to install before:
sudo apt-get install build-essential bison 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
Now, run the RVM installer:
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Then, do the following to load RVM as a function:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
source .bash_profile
Prerequisites
In order to install Rubies, you have to install some additional Ubuntu packages. Enter the following:
rvm notes
This will give you instructions on what to install through apt-get.
Installing Rubies
Now let's get to installing the correct Ruby versions. I suggest you use the latest one. To find a list of all rubies, enter rvm list known. Here, I assume the latest version 1.9.3. This may take a while, be patient:
rvm install 1.9.3
Then, set it as the default Ruby version for your user:
rvm use 1.9.3 --default
Now you can install Rails over gem:
gem install rails
Method 3 – rbenv
rbenv is an alternative to RVM that follows a slightly different approach and is less intrusive with regards to the shell. It is incompatible with RVM, so uninstall that if you want rbenv.
Here's how do install it:
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Finally, restart the shell:
exec $SHELL
Now you can install Ruby versions manually by compiling them into $HOME/.rbenv/versions/, or use ruby-build to get a rbenv install command similar to RVM.