Setting up RVM on Ubuntu
A little while ago I did a post on setting up RVM on the Amazon Machine Image distribution of Linux on EC2. The process for Ubuntu is pretty much identical, but because installation can be such a pain, I decided to give it its own post. So, this is basically the Amazon Linux on EC2 post, but with Ubuntu commands substituted in. Here we go.
Today we'll go over how to set up RVM on Ubuntu. In theory, this should work seamlessly, but often these types of things don't go exactly as planned, so it's understandable if you need to consult other sources as well. Since there are a lot of terrible tutorials out there that lead you astray in trying to install RVM, let's set a few goals, so you'll know what to avoid when you look for more tips.
You should
- Probably not install RVM as root. Your
.rvm
directory should be in$HOME
path, also known as~
- Not use sudo -s or any type of persistent root login unless you are 100% confident that all your commands should be run as root. So often a tutorial will log you in as root, and then end up installing RVM as root.
Additionally, there are certain things we will be doing, but it's not bad practice to do other things.
We will be
- Using Ubuntu Linux.
- Installing RVM at all. (There are other ways to manage rubies—like rbenv—, and you don't have to use RVM at all.)
Anyway, let's dig in. This tutorial assumes you you have a terminal prompt to a Linux box running Ubuntu open. This could be your local machine or perhaps a virtual machine on Amazon EC2; it doesn't matter.
First, let's get everything up to date:
sudo apt-get -y update
apt
stands for "Advanced Packaging Tool," and apt-get
is a standard tool on Ubuntu to download packages.
The -y
option tells the apt-get
command to answer yes to any prompts given during the install. If you omit it, that's fine, you'll just have to hit "Y" when prompted.
Great. Now let's install Git. Git is a DVCS (Distributed Version Control System). Basically, it allows you to take snapshots of your codebase as you develop, document those snapshots, revisit them, and even 'push' them to and 'pull' them from other locations, among other things. If you aren't using version control, you probably should be. Also, RVM depends on Git, so we need it for more than just compliance with my preachings.
sudo apt-get -y install git-core
And let's install curl:
sudo apt-get -y install curl
Awesome. Now let's get down to business. Let's run the script to install RVM (without sudo!).
curl -L get.rvm.io | bash -s stable
The -L tells curl to follow redirects (get.rvm.io redirects us to https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer -- type get.rvm.io into your browser's url bar to see for yourself. You can also try running curl get.rvm.io to see what a redirect looks like, if you haven't before.)
(Small side-note applicable to very few of you: if you are specifically looking to install RVM on a multi-user system for use by all users, you will want to replace the above command with curl -L get.rvm.io | sudo bash -s stable
. If you are confused by this side-note, just proceed with command that does not use sudo at all.)
This installs a .rvm directory in our home folder, just like we wanted. To test this we can say ls -a ~ | grep .rvm
and it should output ".rvm".
RVM also requires bash >= 4.1. Most default ones should be compliant, but let's make sure:
bash --version
(mine is 4.1.5 at the time of this writing).
If your's is less than 4.1 for some reason, run sudo apt-get install bash
to upgrade.
Okay, perfect. In order to use the rvm command, we run:
source ~/.rvm/scripts/rvm
No output means all is going to plan. But we're not done. Let's see what RVM would like us to do next:
rvm requirements
Under Additional Dependencies, it tells us that for Ruby we need to run an apt-get install
command with a whole lot of arguments to get all the dependencies. These are dependencies that we'll want to install as root
, so let's run it:
sudo apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
Okay, now let's get the version of ruby we want up and running.
rvm install 1.9.3
(1.9.3 is the latest stable release).
This may take a while, so feel free to get a snack or call someone you haven't spoken to in a while or something. In the end though, it should work perfectly. I like to have rubygems installed too, so after rvm is done installing ruby for us, if you're like me you'll want to run:
rvm rubygems latest
And that's it! You should be all good to go. Next moves are up to you. You can rvm use --default 1.9.3
, or perhaps gem install bundler
. You might even decide to gem list --local
, or gem install rails
.
A Note on Struggles
Of course, it is not always so easy, and, as is often the case with installation, just because it worked for me does not mean it certainly will for you. It certainly did not work for me the first time. Feel free to look elsewhere for help, just be skeptical in your hobbies of anyone who tells you to install RVM as root!