2013-01-03 13:49:03 -05:00
|
|
|
|
# Groom your app’s Ruby environment with rbenv.
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-02 21:00:04 -05:00
|
|
|
|
Use rbenv to pick a Ruby version for your application and guarantee
|
|
|
|
|
that your development environment matches production. Put rbenv to work
|
2015-02-15 22:03:08 -05:00
|
|
|
|
with [Bundler](http://bundler.io/) for painless Ruby upgrades and
|
2013-01-02 21:00:04 -05:00
|
|
|
|
bulletproof deployments.
|
2013-01-02 19:56:23 -05:00
|
|
|
|
|
2013-01-02 21:00:04 -05:00
|
|
|
|
**Powerful in development.** Specify your app's Ruby version once,
|
|
|
|
|
in a single file. Keep all your teammates on the same page. No
|
|
|
|
|
headaches running apps on different versions of Ruby. Just Works™
|
|
|
|
|
from the command line and with app servers like [Pow](http://pow.cx).
|
|
|
|
|
Override the Ruby version anytime: just set an environment variable.
|
2013-01-02 19:56:23 -05:00
|
|
|
|
|
|
|
|
|
**Rock-solid in production.** Your application's executables are its
|
|
|
|
|
interface with ops. With rbenv and [Bundler
|
2013-01-04 10:19:18 -05:00
|
|
|
|
binstubs](https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs)
|
2013-01-02 19:56:23 -05:00
|
|
|
|
you'll never again need to `cd` in a cron job or Chef recipe to
|
|
|
|
|
ensure you've selected the right runtime. The Ruby version
|
2013-01-02 21:01:47 -05:00
|
|
|
|
dependency lives in one place—your app—so upgrades and rollbacks are
|
|
|
|
|
atomic, even when you switch versions.
|
2013-01-02 19:56:23 -05:00
|
|
|
|
|
|
|
|
|
**One thing well.** rbenv is concerned solely with switching Ruby
|
2013-01-02 21:00:04 -05:00
|
|
|
|
versions. It's simple and predictable. A rich plugin ecosystem lets
|
|
|
|
|
you tailor it to suit your needs. Compile your own Ruby versions, or
|
2013-10-03 14:52:13 -04:00
|
|
|
|
use the [ruby-build][]
|
2013-01-02 21:00:04 -05:00
|
|
|
|
plugin to automate the process. Specify per-application environment
|
|
|
|
|
variables with [rbenv-vars](https://github.com/sstephenson/rbenv-vars).
|
|
|
|
|
See more [plugins on the
|
2013-01-02 19:56:23 -05:00
|
|
|
|
wiki](https://github.com/sstephenson/rbenv/wiki/Plugins).
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-04 13:23:41 -05:00
|
|
|
|
[**Why choose rbenv over
|
|
|
|
|
RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F)
|
|
|
|
|
|
2011-08-11 15:25:08 -04:00
|
|
|
|
## Table of Contents
|
|
|
|
|
|
2012-12-11 20:43:48 -05:00
|
|
|
|
* [How It Works](#how-it-works)
|
2013-01-03 22:18:05 -05:00
|
|
|
|
* [Understanding PATH](#understanding-path)
|
|
|
|
|
* [Understanding Shims](#understanding-shims)
|
|
|
|
|
* [Choosing the Ruby Version](#choosing-the-ruby-version)
|
|
|
|
|
* [Locating the Ruby Installation](#locating-the-ruby-installation)
|
2012-12-11 20:43:48 -05:00
|
|
|
|
* [Installation](#installation)
|
|
|
|
|
* [Basic GitHub Checkout](#basic-github-checkout)
|
|
|
|
|
* [Upgrading](#upgrading)
|
|
|
|
|
* [Homebrew on Mac OS X](#homebrew-on-mac-os-x)
|
2013-12-14 16:38:25 -05:00
|
|
|
|
* [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell)
|
2013-10-03 14:52:13 -04:00
|
|
|
|
* [Installing Ruby Versions](#installing-ruby-versions)
|
2012-12-11 20:43:48 -05:00
|
|
|
|
* [Uninstalling Ruby Versions](#uninstalling-ruby-versions)
|
2015-06-09 17:27:21 -04:00
|
|
|
|
* [Uninstalling rbenv](#uninstalling-rbenv)
|
2013-01-03 11:25:31 -05:00
|
|
|
|
* [Command Reference](#command-reference)
|
2012-12-11 20:43:48 -05:00
|
|
|
|
* [rbenv local](#rbenv-local)
|
2013-01-03 11:39:48 -05:00
|
|
|
|
* [rbenv global](#rbenv-global)
|
2012-12-11 20:43:48 -05:00
|
|
|
|
* [rbenv shell](#rbenv-shell)
|
|
|
|
|
* [rbenv versions](#rbenv-versions)
|
|
|
|
|
* [rbenv version](#rbenv-version)
|
|
|
|
|
* [rbenv rehash](#rbenv-rehash)
|
|
|
|
|
* [rbenv which](#rbenv-which)
|
|
|
|
|
* [rbenv whence](#rbenv-whence)
|
2015-03-13 04:14:24 -04:00
|
|
|
|
* [Environment variables](#environment-variables)
|
2012-12-11 20:43:48 -05:00
|
|
|
|
* [Development](#development)
|
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
## How It Works
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-04 18:14:36 -05:00
|
|
|
|
At a high level, rbenv intercepts Ruby commands using shim
|
2013-01-03 22:18:05 -05:00
|
|
|
|
executables injected into your `PATH`, determines which Ruby version
|
|
|
|
|
has been specified by your application, and passes your commands along
|
|
|
|
|
to the correct Ruby installation.
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### Understanding PATH
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
When you run a command like `ruby` or `rake`, your operating system
|
|
|
|
|
searches through a list of directories to find an executable file with
|
|
|
|
|
that name. This list of directories lives in an environment variable
|
|
|
|
|
called `PATH`, with each directory in the list separated by a colon:
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
/usr/local/bin:/usr/bin:/bin
|
|
|
|
|
|
|
|
|
|
Directories in `PATH` are searched from left to right, so a matching
|
|
|
|
|
executable in a directory at the beginning of the list takes
|
|
|
|
|
precedence over another one at the end. In this example, the
|
|
|
|
|
`/usr/local/bin` directory will be searched first, then `/usr/bin`,
|
|
|
|
|
then `/bin`.
|
|
|
|
|
|
|
|
|
|
### Understanding Shims
|
|
|
|
|
|
|
|
|
|
rbenv works by inserting a directory of _shims_ at the front of your
|
|
|
|
|
`PATH`:
|
|
|
|
|
|
|
|
|
|
~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin
|
|
|
|
|
|
|
|
|
|
Through a process called _rehashing_, rbenv maintains shims in that
|
|
|
|
|
directory to match every Ruby command across every installed version
|
|
|
|
|
of Ruby—`irb`, `gem`, `rake`, `rails`, `ruby`, and so on.
|
|
|
|
|
|
|
|
|
|
Shims are lightweight executables that simply pass your command along
|
|
|
|
|
to rbenv. So with rbenv installed, when you run, say, `rake`, your
|
|
|
|
|
operating system will do the following:
|
|
|
|
|
|
|
|
|
|
* Search your `PATH` for an executable file named `rake`
|
|
|
|
|
* Find the rbenv shim named `rake` at the beginning of your `PATH`
|
|
|
|
|
* Run the shim named `rake`, which in turn passes the command along to
|
|
|
|
|
rbenv
|
|
|
|
|
|
|
|
|
|
### Choosing the Ruby Version
|
|
|
|
|
|
|
|
|
|
When you execute a shim, rbenv determines which Ruby version to use by
|
|
|
|
|
reading it from the following sources, in this order:
|
|
|
|
|
|
|
|
|
|
1. The `RBENV_VERSION` environment variable, if specified. You can use
|
|
|
|
|
the [`rbenv shell`](#rbenv-shell) command to set this environment
|
|
|
|
|
variable in your current shell session.
|
|
|
|
|
|
2013-08-06 16:40:39 -04:00
|
|
|
|
2. The first `.ruby-version` file found by searching the directory of the
|
|
|
|
|
script you are executing and each of its parent directories until reaching
|
|
|
|
|
the root of your filesystem.
|
|
|
|
|
|
|
|
|
|
3. The first `.ruby-version` file found by searching the current working
|
|
|
|
|
directory and each of its parent directories until reaching the root of your
|
|
|
|
|
filesystem. You can modify the `.ruby-version` file in the current working
|
|
|
|
|
directory with the [`rbenv local`](#rbenv-local) command.
|
2013-01-03 22:18:05 -05:00
|
|
|
|
|
|
|
|
|
4. The global `~/.rbenv/version` file. You can modify this file using
|
|
|
|
|
the [`rbenv global`](#rbenv-global) command. If the global version
|
|
|
|
|
file is not present, rbenv assumes you want to use the "system"
|
|
|
|
|
Ruby—i.e. whatever version would be run if rbenv weren't in your
|
|
|
|
|
path.
|
|
|
|
|
|
|
|
|
|
### Locating the Ruby Installation
|
|
|
|
|
|
|
|
|
|
Once rbenv has determined which version of Ruby your application has
|
|
|
|
|
specified, it passes the command along to the corresponding Ruby
|
|
|
|
|
installation.
|
|
|
|
|
|
|
|
|
|
Each Ruby version is installed into its own directory under
|
|
|
|
|
`~/.rbenv/versions`. For example, you might have these versions
|
|
|
|
|
installed:
|
|
|
|
|
|
|
|
|
|
* `~/.rbenv/versions/1.8.7-p371/`
|
|
|
|
|
* `~/.rbenv/versions/1.9.3-p327/`
|
|
|
|
|
* `~/.rbenv/versions/jruby-1.7.1/`
|
|
|
|
|
|
|
|
|
|
Version names to rbenv are simply the names of the directories in
|
|
|
|
|
`~/.rbenv/versions`.
|
|
|
|
|
|
|
|
|
|
## Installation
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-03 11:09:22 -05:00
|
|
|
|
**Compatibility note**: rbenv is _incompatible_ with RVM. Please make
|
|
|
|
|
sure to fully uninstall RVM and remove any references to it from
|
|
|
|
|
your shell initialization files before installing rbenv.
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
If you're on Mac OS X, consider
|
|
|
|
|
[installing with Homebrew](#homebrew-on-mac-os-x).
|
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### Basic GitHub Checkout
|
2011-09-28 14:05:29 -04:00
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
|
This will get you going with the latest version of rbenv and make it
|
|
|
|
|
easy to fork and contribute any changes back upstream.
|
2011-08-11 14:28:02 -04:00
|
|
|
|
|
2011-08-11 13:51:35 -04:00
|
|
|
|
1. Check out rbenv into `~/.rbenv`.
|
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~ sh
|
2013-03-29 11:06:26 -04:00
|
|
|
|
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
|
2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
|
|
|
|
|
command-line utility.
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~ sh
|
|
|
|
|
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
|
|
|
|
|
~~~
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-10-03 14:07:22 -04:00
|
|
|
|
**Ubuntu Desktop note**: Modify your `~/.bashrc` instead of `~/.bash_profile`.
|
2011-09-28 11:13:28 -04:00
|
|
|
|
|
2013-01-04 11:58:38 -05:00
|
|
|
|
**Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`.
|
2012-12-09 17:53:57 -05:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
3. Add `rbenv init` to your shell to enable shims and autocompletion.
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~ sh
|
|
|
|
|
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
|
|
|
|
|
~~~
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-10-03 14:07:22 -04:00
|
|
|
|
_Same as in previous step, use `~/.bashrc` on Ubuntu, or `~/.zshrc` for Zsh._
|
2011-09-28 14:27:42 -04:00
|
|
|
|
|
2013-10-03 14:07:22 -04:00
|
|
|
|
4. Restart your shell so that PATH changes take effect. (Opening a new
|
|
|
|
|
terminal tab will usually do it.) Now check if rbenv was set up:
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~ sh
|
2013-10-03 14:07:22 -04:00
|
|
|
|
$ type rbenv
|
|
|
|
|
#=> "rbenv is a function"
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-10-03 14:52:13 -04:00
|
|
|
|
5. _(Optional)_ Install [ruby-build][], which provides the
|
|
|
|
|
`rbenv install` command that simplifies the process of
|
|
|
|
|
[installing new Ruby versions](#installing-ruby-versions).
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
#### Upgrading
|
2011-09-28 12:20:36 -04:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
If you've installed rbenv manually using git, you can upgrade your
|
|
|
|
|
installation to the cutting-edge version at any time.
|
2011-09-28 12:20:36 -04:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~ sh
|
|
|
|
|
$ cd ~/.rbenv
|
|
|
|
|
$ git pull
|
|
|
|
|
~~~
|
2011-09-28 12:20:36 -04:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
To use a specific release of rbenv, check out the corresponding tag:
|
2011-09-28 12:20:36 -04:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~ sh
|
|
|
|
|
$ cd ~/.rbenv
|
|
|
|
|
$ git fetch
|
2013-01-03 22:18:05 -05:00
|
|
|
|
$ git checkout v0.3.0
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~
|
2011-09-28 12:20:36 -04:00
|
|
|
|
|
2013-10-03 14:52:13 -04:00
|
|
|
|
If you've [installed via Homebrew](#homebrew-on-mac-os-x), then upgrade
|
|
|
|
|
via its `brew` command:
|
|
|
|
|
|
|
|
|
|
~~~ sh
|
|
|
|
|
$ brew update
|
|
|
|
|
$ brew upgrade rbenv ruby-build
|
|
|
|
|
~~~
|
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### Homebrew on Mac OS X
|
2011-09-28 13:19:36 -04:00
|
|
|
|
|
2013-10-03 14:52:13 -04:00
|
|
|
|
As an alternative to installation via GitHub checkout, you can install
|
|
|
|
|
rbenv and [ruby-build][] using the [Homebrew](http://brew.sh) package
|
|
|
|
|
manager on Mac OS X:
|
2011-09-28 13:19:36 -04:00
|
|
|
|
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~
|
|
|
|
|
$ brew update
|
2013-10-03 14:52:13 -04:00
|
|
|
|
$ brew install rbenv ruby-build
|
2012-12-12 17:46:10 -05:00
|
|
|
|
~~~
|
2011-09-28 14:05:29 -04:00
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
|
Afterwards you'll still need to add `eval "$(rbenv init -)"` to your
|
|
|
|
|
profile as stated in the caveats. You'll only ever have to do this
|
|
|
|
|
once.
|
2011-09-28 14:05:29 -04:00
|
|
|
|
|
2013-12-14 16:38:25 -05:00
|
|
|
|
### How rbenv hooks into your shell
|
2011-09-28 14:05:29 -04:00
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
|
Skip this section unless you must know what every line in your shell
|
|
|
|
|
profile is doing.
|
2011-09-28 14:05:29 -04:00
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
|
`rbenv init` is the only command that crosses the line of loading
|
2013-01-04 17:17:52 -05:00
|
|
|
|
extra commands into your shell. Coming from RVM, some of you might be
|
2011-09-28 14:35:17 -04:00
|
|
|
|
opposed to this idea. Here's what `rbenv init` actually does:
|
2011-09-28 14:05:29 -04:00
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
|
1. Sets up your shims path. This is the only requirement for rbenv to
|
2011-09-28 14:35:17 -04:00
|
|
|
|
function properly. You can do this by hand by prepending
|
2011-09-28 14:27:42 -04:00
|
|
|
|
`~/.rbenv/shims` to your `$PATH`.
|
|
|
|
|
|
|
|
|
|
2. Installs autocompletion. This is entirely optional but pretty
|
|
|
|
|
useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that
|
2011-09-28 14:29:37 -04:00
|
|
|
|
up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh
|
2011-09-28 14:27:42 -04:00
|
|
|
|
users.
|
|
|
|
|
|
2011-09-28 14:35:17 -04:00
|
|
|
|
3. Rehashes shims. From time to time you'll need to rebuild your
|
2013-01-04 17:17:52 -05:00
|
|
|
|
shim files. Doing this automatically makes sure everything is up to
|
2011-09-28 14:35:17 -04:00
|
|
|
|
date. You can always run `rbenv rehash` manually.
|
2011-09-28 14:27:42 -04:00
|
|
|
|
|
2011-09-28 14:35:17 -04:00
|
|
|
|
4. Installs the sh dispatcher. This bit is also optional, but allows
|
|
|
|
|
rbenv and plugins to change variables in your current shell, making
|
|
|
|
|
commands like `rbenv shell` possible. The sh dispatcher doesn't do
|
|
|
|
|
anything crazy like override `cd` or hack your shell prompt, but if
|
|
|
|
|
for some reason you need `rbenv` to be a real script rather than a
|
|
|
|
|
shell function, you can safely skip it.
|
2011-09-28 13:19:36 -04:00
|
|
|
|
|
2011-09-28 14:35:17 -04:00
|
|
|
|
Run `rbenv init -` for yourself to see exactly what happens under the
|
|
|
|
|
hood.
|
2011-09-28 13:19:36 -04:00
|
|
|
|
|
2013-10-03 14:52:13 -04:00
|
|
|
|
### Installing Ruby Versions
|
|
|
|
|
|
|
|
|
|
The `rbenv install` command doesn't ship with rbenv out of the box, but
|
|
|
|
|
is provided by the [ruby-build][] project. If you installed it either
|
|
|
|
|
as part of GitHub checkout process outlined above or via Homebrew, you
|
|
|
|
|
should be able to:
|
|
|
|
|
|
|
|
|
|
~~~ sh
|
|
|
|
|
# list all available versions:
|
|
|
|
|
$ rbenv install -l
|
|
|
|
|
|
|
|
|
|
# install a Ruby version:
|
2013-10-03 16:10:44 -04:00
|
|
|
|
$ rbenv install 2.0.0-p247
|
2013-10-03 14:52:13 -04:00
|
|
|
|
~~~
|
|
|
|
|
|
|
|
|
|
Alternatively to the `install` command, you can download and compile
|
|
|
|
|
Ruby manually as a subdirectory of `~/.rbenv/versions/`. An entry in
|
|
|
|
|
that directory can also be a symlink to a Ruby version installed
|
|
|
|
|
elsewhere on the filesystem. rbenv doesn't care; it will simply treat
|
|
|
|
|
any entry in the `versions/` directory as a separate Ruby version.
|
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### Uninstalling Ruby Versions
|
2012-02-03 01:48:20 -05:00
|
|
|
|
|
2013-01-03 11:20:52 -05:00
|
|
|
|
As time goes on, Ruby versions you install will accumulate in your
|
2012-02-03 01:48:20 -05:00
|
|
|
|
`~/.rbenv/versions` directory.
|
|
|
|
|
|
2013-01-03 11:20:52 -05:00
|
|
|
|
To remove old Ruby versions, simply `rm -rf` the directory of the
|
|
|
|
|
version you want to remove. You can find the directory of a particular
|
2013-01-04 17:17:52 -05:00
|
|
|
|
Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix
|
2013-01-03 11:20:52 -05:00
|
|
|
|
1.8.7-p357`.
|
|
|
|
|
|
2013-10-03 14:52:13 -04:00
|
|
|
|
The [ruby-build][] plugin provides an `rbenv uninstall` command to
|
|
|
|
|
automate the removal process.
|
2012-02-03 01:48:20 -05:00
|
|
|
|
|
2015-06-09 17:27:21 -04:00
|
|
|
|
### Uninstalling rbenv
|
|
|
|
|
|
|
|
|
|
The simplicity of rbenv makes it easy to temporarily disable it, or
|
|
|
|
|
uninstall from the system.
|
|
|
|
|
|
|
|
|
|
1. To **disable** rbenv managing your Ruby versions, simply remove the
|
|
|
|
|
`rbenv init` line from your shell startup configuration. This will
|
|
|
|
|
remove rbenv shims directory from PATH, and future invocations like
|
|
|
|
|
`ruby` will execute the system Ruby version, as before rbenv.
|
|
|
|
|
|
|
|
|
|
`rbenv` will still be accessible on the command line, but your Ruby
|
|
|
|
|
apps won't be affected by version switching.
|
|
|
|
|
|
|
|
|
|
2. To completely **uninstall** rbenv, perform step (1) and then remove
|
|
|
|
|
its root directory. This will **delete all Ruby versions** that were
|
|
|
|
|
installed under `` `rbenv root`/versions/ `` directory:
|
|
|
|
|
|
|
|
|
|
rm -rf `rbenv root`
|
|
|
|
|
|
|
|
|
|
If you've installed rbenv using a package manager, as a final step
|
|
|
|
|
perform the rbenv package removal. For instance, for Homebrew:
|
|
|
|
|
|
|
|
|
|
brew uninstall rbenv
|
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
## Command Reference
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2011-08-11 14:11:37 -04:00
|
|
|
|
Like `git`, the `rbenv` command delegates to subcommands based on its
|
|
|
|
|
first argument. The most common subcommands are:
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### rbenv local
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-03 11:00:10 -05:00
|
|
|
|
Sets a local application-specific Ruby version by writing the version
|
|
|
|
|
name to a `.ruby-version` file in the current directory. This version
|
2013-01-03 11:39:48 -05:00
|
|
|
|
overrides the global version, and can be overridden itself by setting
|
|
|
|
|
the `RBENV_VERSION` environment variable or with the `rbenv shell`
|
2011-09-28 11:13:28 -04:00
|
|
|
|
command.
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-03 11:39:48 -05:00
|
|
|
|
$ rbenv local 1.9.3-p327
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2011-08-18 13:57:36 -04:00
|
|
|
|
When run without a version number, `rbenv local` reports the currently
|
2011-09-28 11:13:28 -04:00
|
|
|
|
configured local version. You can also unset the local version:
|
|
|
|
|
|
|
|
|
|
$ rbenv local --unset
|
|
|
|
|
|
2012-12-31 10:58:28 -05:00
|
|
|
|
Previous versions of rbenv stored local version specifications in a
|
|
|
|
|
file named `.rbenv-version`. For backwards compatibility, rbenv will
|
|
|
|
|
read a local version specified in an `.rbenv-version` file, but a
|
|
|
|
|
`.ruby-version` file in the same directory will take precedence.
|
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### rbenv global
|
2013-01-03 11:39:48 -05:00
|
|
|
|
|
|
|
|
|
Sets the global version of Ruby to be used in all shells by writing
|
|
|
|
|
the version name to the `~/.rbenv/version` file. This version can be
|
|
|
|
|
overridden by an application-specific `.ruby-version` file, or by
|
|
|
|
|
setting the `RBENV_VERSION` environment variable.
|
|
|
|
|
|
|
|
|
|
$ rbenv global 1.8.7-p352
|
|
|
|
|
|
|
|
|
|
The special version name `system` tells rbenv to use the system Ruby
|
|
|
|
|
(detected by searching your `$PATH`).
|
|
|
|
|
|
|
|
|
|
When run without a version number, `rbenv global` reports the
|
|
|
|
|
currently configured global version.
|
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### rbenv shell
|
2011-09-28 11:13:28 -04:00
|
|
|
|
|
|
|
|
|
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
|
2013-01-03 11:00:10 -05:00
|
|
|
|
environment variable in your shell. This version overrides
|
|
|
|
|
application-specific versions and the global version.
|
2011-09-28 11:13:28 -04:00
|
|
|
|
|
2012-12-11 15:56:03 -05:00
|
|
|
|
$ rbenv shell jruby-1.7.1
|
2011-09-28 11:13:28 -04:00
|
|
|
|
|
|
|
|
|
When run without a version number, `rbenv shell` reports the current
|
|
|
|
|
value of `RBENV_VERSION`. You can also unset the shell version:
|
|
|
|
|
|
|
|
|
|
$ rbenv shell --unset
|
|
|
|
|
|
|
|
|
|
Note that you'll need rbenv's shell integration enabled (step 3 of
|
|
|
|
|
the installation instructions) in order to use this command. If you
|
|
|
|
|
prefer not to use shell integration, you may simply set the
|
|
|
|
|
`RBENV_VERSION` variable yourself:
|
|
|
|
|
|
2012-12-11 15:56:03 -05:00
|
|
|
|
$ export RBENV_VERSION=jruby-1.7.1
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### rbenv versions
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2011-08-11 15:21:15 -04:00
|
|
|
|
Lists all Ruby versions known to rbenv, and shows an asterisk next to
|
|
|
|
|
the currently active version.
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2011-08-11 15:21:15 -04:00
|
|
|
|
$ rbenv versions
|
|
|
|
|
1.8.7-p352
|
|
|
|
|
1.9.2-p290
|
2012-12-31 10:58:28 -05:00
|
|
|
|
* 1.9.3-p327 (set by /Users/sam/.rbenv/version)
|
2012-12-11 15:56:03 -05:00
|
|
|
|
jruby-1.7.1
|
2011-08-11 15:21:15 -04:00
|
|
|
|
rbx-1.2.4
|
|
|
|
|
ree-1.8.7-2011.03
|
2011-08-11 14:25:54 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### rbenv version
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
|
|
|
|
Displays the currently active Ruby version, along with information on
|
|
|
|
|
how it was set.
|
|
|
|
|
|
|
|
|
|
$ rbenv version
|
2015-02-16 10:56:38 -05:00
|
|
|
|
1.9.3-p327 (set by /Users/sam/.rbenv/version)
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### rbenv rehash
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
2013-01-03 11:06:12 -05:00
|
|
|
|
Installs shims for all Ruby executables known to rbenv (i.e.,
|
2011-08-11 15:21:15 -04:00
|
|
|
|
`~/.rbenv/versions/*/bin/*`). Run this command after you install a new
|
2013-01-03 11:06:12 -05:00
|
|
|
|
version of Ruby, or install a gem that provides commands.
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
|
|
|
|
$ rbenv rehash
|
2011-08-11 14:25:54 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### rbenv which
|
2011-09-28 11:48:04 -04:00
|
|
|
|
|
2013-01-03 11:06:12 -05:00
|
|
|
|
Displays the full path to the executable that rbenv will invoke when
|
|
|
|
|
you run the given command.
|
2011-09-28 11:48:04 -04:00
|
|
|
|
|
|
|
|
|
$ rbenv which irb
|
2012-11-17 02:57:23 -05:00
|
|
|
|
/Users/sam/.rbenv/versions/1.9.3-p327/bin/irb
|
2011-09-28 11:48:04 -04:00
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
### rbenv whence
|
2011-09-28 11:48:04 -04:00
|
|
|
|
|
|
|
|
|
Lists all Ruby versions with the given command installed.
|
|
|
|
|
|
|
|
|
|
$ rbenv whence rackup
|
2012-11-17 02:57:23 -05:00
|
|
|
|
1.9.3-p327
|
2012-12-11 15:56:03 -05:00
|
|
|
|
jruby-1.7.1
|
2011-09-28 11:48:04 -04:00
|
|
|
|
ree-1.8.7-2011.03
|
|
|
|
|
|
2015-03-13 04:14:24 -04:00
|
|
|
|
## Environment variables
|
|
|
|
|
|
|
|
|
|
You can affect how rbenv operates with the following settings:
|
|
|
|
|
|
|
|
|
|
name | default | description
|
|
|
|
|
-----|---------|------------
|
|
|
|
|
`RBENV_VERSION` | | Specifies the Ruby version to be used.<br>Also see [`rbenv shell`](#rbenv-shell)
|
|
|
|
|
`RBENV_ROOT` | `~/.rbenv` | Defines the directory under which Ruby versions and shims reside.<br>Also see `rbenv root`
|
|
|
|
|
`RBENV_DEBUG` | | Outputs debug information.<br>Also as: `rbenv --debug <subcommand>`
|
|
|
|
|
`RBENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for rbenv hooks.
|
|
|
|
|
`RBENV_DIR` | `$PWD` | Directory to start searching for `.ruby-version` files.
|
|
|
|
|
|
2013-01-03 22:18:05 -05:00
|
|
|
|
## Development
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2011-08-11 14:11:37 -04:00
|
|
|
|
The rbenv source code is [hosted on
|
|
|
|
|
GitHub](https://github.com/sstephenson/rbenv). It's clean, modular,
|
|
|
|
|
and easy to understand, even if you're not a shell hacker.
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-03-07 15:05:49 -05:00
|
|
|
|
Tests are executed using [Bats](https://github.com/sstephenson/bats):
|
|
|
|
|
|
|
|
|
|
$ bats test
|
|
|
|
|
$ bats test/<file>.bats
|
|
|
|
|
|
2011-08-11 14:11:37 -04:00
|
|
|
|
Please feel free to submit pull requests and file bugs on the [issue
|
|
|
|
|
tracker](https://github.com/sstephenson/rbenv/issues).
|
2011-08-11 13:51:35 -04:00
|
|
|
|
|
2013-10-03 14:52:13 -04:00
|
|
|
|
|
|
|
|
|
[ruby-build]: https://github.com/sstephenson/ruby-build#readme
|
2015-03-13 04:14:24 -04:00
|
|
|
|
[hooks]: https://github.com/sstephenson/rbenv/wiki/Authoring-plugins#rbenv-hooks
|