Installing Ruby with RVM

Before you can deploy your app on the production server, you need to install Ruby. In this tutorial we recommend that you use Ruby Version Manager (RVM) for this purpose. RVM is a tool for installing and managing multiple Ruby versions.

There are other ways to install Ruby, e.g. through yum, apt-get, source tarball, rbenv and chruby. You can use one of those other installation methods if you so wish, and this tutorial will work fine even if you installed Ruby using one of those other installation methods. But the one that we recommend in this tutorial is RVM, because in our opinion it is the easiest option.

If you have already installed Ruby, then you can skip to the next page.

Table of contents

  1. Loading...

Prepare the system

Ensure that curl and gpg are installed, as well as a compiler toolchain. Curl and gpg are needed for further installation steps, while the compiler toolchain is needed for installing common Ruby gems.

Debian, Ubuntu
sudo apt-get update
sudo apt-get install -y curl gnupg build-essential
Red Hat, CentOS, Fedora, Amazon Linux, Scientific Linux
sudo yum install -y curl gpg gcc gcc-c++ make
Mac OS X You don't have to do anything. They are already installed.

Install RVM

Run the following commands on your production server to install RVM:

$ sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ curl -sSL https://get.rvm.io | sudo bash -s stable
$ sudo usermod -a -G rvm `whoami`

You may need to use gpg2 instead of gpg on some systems.

On systems where sudo is configured with secure_path, the shell environment needs to be modified to set rvmsudo_secure_path=1. secure_path is set on most Linux systems, but not on OS X. The following command tries to autodetect whether it is necessary to install rvmsudo_secure_path=1, and only installs the environment variable if it is the code.

$ if sudo grep -q secure_path /etc/sudoers; then sudo sh -c "echo export rvmsudo_secure_path=1 >> /etc/profile.d/rvm_secure_path.sh" && echo Environment variable installed; fi

When you are done with all this, relogin to your server to activate RVM. This is important: if you don't relogin, RVM doesn't work. Also if you use gnu screen or another terminal multiplexer, RVM also won't work; you must use a plain ssh session.

Install the Ruby version you want

Usually, installing the latest Ruby version will suffice. If you are deploying the example app from the quickstart, then that example application works with all Ruby versions.

However, if you are deploying your own app, then your app may have a specific Ruby version requirement.

To install the latest version of Ruby, run:

$ rvm install ruby
$ rvm --default use ruby

To install a specific version of Ruby, run:

$ rvm install ruby-X.X.X
$ rvm --default use ruby-X.X.X

Replace X.X.X with the Ruby version you want.

Install Bundler

Bundler is a popular tool for managing application gem dependencies. We will use Bundler in this tutorial, so let us install it:

$ gem install bundler --no-rdoc --no-ri

Optional: install Node.js if you're using Rails

If you are using Rails, then you must install Node.js. This is because Rails's asset pipeline compiler requires a Javascript runtime. The Node.js version does not matter.

If you do not use Rails then you can skip to the next step.

To install Node.js:

Ubuntu
sudo apt-get install -y nodejs &&
sudo ln -sf /usr/bin/nodejs /usr/local/bin/node
Debian >= 8 (Jessie or later)
sudo apt-get install -y nodejs &&
sudo ln -sf /usr/bin/nodejs /usr/local/bin/node
Debian 7 (Wheezy)

Run the following commands to install Node.js from the NodeSource APT repository.

sudo apt-get update &&
sudo apt-get install -y apt-transport-https ca-certificates &&
curl --fail -ssL -o setup-nodejs https://deb.nodesource.com/setup_0.12 &&
sudo bash setup-nodejs &&
sudo apt-get install -y nodejs
Red Hat, CentOS, Fedora, Amazon Linux, Scientific Linux
sudo yum install -y epel-release
sudo yum install -y --enablerepo=epel nodejs npm
Other operating systems Please install Node.js from www.nodejs.org.

Heads-up: sudo vs rvmsudo

One thing you should be aware of when using RVM, is that you should use rvmsudo instead of sudo when executing Ruby-related commands. This is because RVM works by manipulating environment variables. However, sudo nukes all environment variables for security reasons, which intereferes with RVM.

Visit the RVM website to learn more about rvmsudo.

Next step

Congratulations, you have installed Ruby on your production server!

Continue: Install Passenger »