---
title: "Changing Ruby versions"
date: "2015-01-06"
category: "ruby"
slug: "changing-ruby-versions"
---

## Overview

[[determining-platform-version]] v6+ support multiple Ruby versions through [rvm](http://www.rvm.io), enabling you to run multiple versions of Rack and Rails using any available Ruby interpreter. Currently, versions 1.8 through 2.2 are supported.

**Important:** Avoid Ruby 1.8 except to shim an older application while planning an upgrade. Ruby 1.8 is [deprecated](https://www.ruby-lang.org/en/news/2011/10/06/plans-for-1-8-7/) and contains unpatched security vulnerabilities.

## Switching Versions

All commands are run from the [[accessing-terminal]].

### Listing Available Versions

Use `rvm list` to see installed Ruby versions. If the version you need is missing, open a ticket to request installation.

[myadmin]$ rvm list
rvm rubies
   ruby-1.8.7-head [ x86\_64 ]
   ruby-1.8.7-p374 [ x86\_64 ]
   ruby-1.9.3-p547 [ x86\_64 ]
 \* ruby-2.0.0-p481 [ x86\_64 ]
=> ruby-2.1.2 [ x86\_64 ]
   ruby-head [ x86\_64 ]
# => - current
# =\* - current && default
# \*  - default

- `=>` indicates the currently active version (reported by `ruby --version`)
- `*` indicates the default version used on login without issuing `rvm use`

### Setting the Version for a Session

Use `rvm use ruby-ver` to set the Ruby version for the current session:

[myadmin]$ rvm use ruby-head
ruby-head - #gemset created /home/myadmin/.rvm/gems/ruby-head
ruby-head - #importing gemsetfile /.socket/ruby/gemsets/default.gems evaluated to empty gem list
ruby-head - #generating default wrappers.............
Using /home/myadmin/.rvm/gems/ruby-head

If Rubygems has not been initialized for the selected version, gems will be populated automatically. Use `rvm use --default ruby-ver` to set it as your default for future logins.

Note: `rvm list` shows the server default, which may differ from your personal default set via `rvm use --default`.

### Setting the Version Per Directory

You can set a default Ruby version for a directory and all its subdirectories using a `.ruby-version` file. For example, to use Ruby 2.2.4 for everything under `/var/www`:

echo "ruby-2.2.4" > /var/www/.ruby-version
ruby -v
# Ruby version will be system default
cd /
# Leave /var/www
cd /var/www
# Ruby version now queried from /var/www/.ruby-version
ruby -v
# Ruby version will output ruby 2.2.4p230

This applies to all subdirectories, including `/var/www/myapp`, `/var/www/domain2.com/app1`, etc.

## See Also

- [[setting-rails-passenger]]
