How to install RVM (Ruby Version Manager)

Here are few steps that I recommend to do on newly installed ubuntu machine. Let’s say you just installed rails-dev-box vagrant virtual machine, or you have fresh ubuntu installation – it doesn’t matter – developers use different versions of Ruby. So how to manage them?

Well, it was already mentioned a couple of thousand times, but things are little bit different over the years. In this article we’ll install Ruby Version Manager (RVM) for ubuntu. With few really minor modifications it should also work for Mac OS X.

For the sake of simplicity I usually run sudo bash command before. So you don’t need to run sudo something every time.

The first step – update a list of packages:

apt-get update

Next, I had no proper certificates on my fresh ubuntu machine for downloading RVM. Run this:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

After that we can download and install RVM itself:

curl -L get.rvm.io | bash -s stable

It’s “almost complete” according to the message. So you need to run few additional commands:

source /etc/profile.d/rvm.sh

And

rvm requirements

The last one will detect and download all RVM requirements. And finally we can install ruby binaries. The command itself is very easy:

rvm install VERSION

But you have to know what VERSION you want to install. If you want to install 2.2.0, just type:

rvm install 2.2.0

But how to know which version you need to install? Well, that’s easy. But there are few scenarios. How are you going to use the current virtual machine?

* If you planning to run rails app downloaded from someone’s Github page, just go application directory and locate .ruby-version file. You’ll see ruby version required to run the app.

* If you running your own app, look at your .ruby-version. If you don’t have one, run ruby --version command from your development shell. This is why it’s very important to have your .ruby-version for your app.

* If you don’t know, go to ruby downloads page and look for the “latest stable version is…”

Keep in mind with version manager you can install multiple ruby binaries. And only one of them you can make default. Go back to your shell and type:

rvm use 2.2.0 --default

And now you can install rails gem:

gem install rails

Try to log in as a normal user or type “exit” if you’re under the root user. Let’s check if you can install gems under the standard user:


ro@ubuntu:~$ gem install foreman
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/local/rvm/gems/ruby-2.2.0 directory.

If you have this error, just execute the command with path to directory above:


sudo chmod -R 777 /usr/local/rvm/gems/ruby-2.2.0

Good luck!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s