Setting up RVM on Amazon EC2
Today I'm going over how to set up RVM on an Amazon EC2 server. This should work seamlessly if you have used Amazon EC2 before, 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 the first option, the Amazon Linux AMI (that's Amazon Machine Image), that is offered in the signup wizard. 64 bit.
- 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 have launched an instance, created a keypair and a security group allowing SSH, and have SSH'ed in to your instance.You should have a prompt like:[ec2-user@ip-10-128-47-32 ~]$
(the IP address will vary).
First, let's make sure everything is up to date. It will probably be if you just launched the instance:
sudo yum -y update
yum
stands for "Yellow Dog Updater Modified" (Yellow Dog is a distribution of Linux), and it's the default package installer on the AMI we are using. On other versions of Linux, you might use apt-get
instead.
The -y
option tells yum
to answer yes to any prompts given during the install.
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 yum -y install git
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.
If for some reason curl isn't installed, run sudo yum install curl
before trying the above line again.
RVM also requires bash >= 4.1. The default version on the AMI we are using should be compliant, but let's make sure:
<code>bash --version</code>
(mine is 4.1.2 at the time of this writing).
If your's is less than 4.1 for some reason, run sudo yum 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 a yum 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 yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel
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 of anyone who tells you to install RVM as root!