Simple Ruby Version Management: rbenv
rbenv lets you easily switch between multiple versions of Ruby. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.
- Let you change the default Ruby version on a per-user basis.
- Provide support for per-project Ruby versions.
- Allow you to override the Ruby version with an environment variable.
In contrast with rvm, rbenv does not…
- Need to be loaded into your shell. Instead, rbenv's shim
approach works by adding a directory to your
- Override shell commands like
cd. That's dangerous and error-prone.
- Have a configuration file. There's nothing to configure except which version of Ruby you want to use.
- Install Ruby. You can build and install Ruby yourself, or use ruby-build to automate the process.
- Manage gemsets. Bundler is a better way to manage application dependencies. If you have projects that are not yet using Bundler you can install the rbenv-gemset plugin.
- Require changes to Ruby libraries for compatibility. The
simplicity of rbenv means as long as it's in your
$PATH, nothing else needs to know about it.
- Prompt you with warnings when you switch to a project. Instead of executing arbitrary code, rbenv reads just the version name from each project. There's nothing to "trust."
Table of Contents
- 1 How It Works
- 2 Installation
- 3 Usage
- 4 Contributing
rbenv operates on the per-user directory
~/.rbenv. Version names in
rbenv correspond to subdirectories of
example, you might have
Each version is a working tree with its own binaries, like
~/.rbenv/versions/1.9.3-preview1/irb. rbenv makes shim binaries
for every such binary across all installed versions of Ruby.
These shims are simple wrapper scripts that live in
and detect which Ruby version you want to use. They insert the
directory for the selected version at the beginning of your
and then execute the corresponding binary.
Because of the simplicity of the shim approach, all you need to use
~/.rbenv/shims in your
rbenv is a young project, so for now you must install it from source.
Compatibility note: rbenv is incompatible with rvm. Things will
appear to work until you try to install a gem. The problem is that
rvm actually overrides the
gem command with a shell function!
Please remove any references to rvm before using rbenv.
Check out rbenv into
$ cd $ git clone git://github.com/sstephenson/rbenv.git .rbenv
$PATHfor access to the
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile
Add rbenv's shims directory to your
$PATHand set up Bash autocompletion. (If you prefer not to load rbenv in your shell, you can manually add
$HOME/.rbenv/shimsto your path in step 2.)
$ echo 'eval "$(rbenv init -)"' >> .bash_profile
Restart your shell. You can now begin using rbenv.
Install Ruby versions into
~/.rbenv/versions. For example, to install Ruby 1.9.2-p290, download and unpack the source, then run:
$ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290 $ make $ make install
The ruby-build project simplifies this process to a single command:
$ ruby-build 1.9.2-p290 $HOME/.rbenv/versions/1.9.2-p290
Rebuild the shim binaries. You should do this any time you install a new Ruby binary (for example, when installing a new Ruby version, or when installing a gem that provides a binary).
$ rbenv rehash
rbenv command delegates to subcommands based on its
first argument. The most common subcommands are:
Sets the default version of Ruby to be used in all shells by writing
the version name to the
~/.rbenv/default file. This version can be
overridden by a per-project
.rbenv-version file, or by setting the
RBENV_VERSION environment variable.
$ rbenv set-default 1.9.2-p290
The special version name
system tells rbenv to use the system Ruby
(detected by searching your
Sets a local per-project Ruby version by writing the version name to
.rbenv-version file in the current directory. This version
overrides the default, and can be overridden itself by setting the
RBENV_VERSION environment variable.
$ rbenv set-local rbx-1.2.4
Lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version.
$ rbenv versions 1.8.7-p352 1.9.2-p290 * 1.9.3-preview1 (set by /Users/sam/.rbenv/default) jruby-1.6.3 rbx-1.2.4 ree-1.8.7-2011.03
Displays the currently active Ruby version, along with information on how it was set.
$ rbenv version 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version)
Installs shims for all Ruby binaries known to rbenv (i.e.,
~/.rbenv/versions/*/bin/*). Run this command after you install a new
version of Ruby, or install a gem that provides binaries.
$ rbenv rehash
The rbenv source code is hosted on GitHub. It's clean, modular, and easy to understand, even if you're not a shell hacker.
Please feel free to submit pull requests and file bugs on the issue tracker.
(The MIT license)
Copyright (c) 2011 Sam Stephenson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.