2011-08-11 15:21:15 -04:00
|
|
|
# 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.
|
|
|
|
|
2011-09-28 13:08:08 -04:00
|
|
|
<img src="http://i.sstephenson.us/rbenv.png" width="894" height="464">
|
|
|
|
|
2011-08-11 15:21:15 -04:00
|
|
|
### rbenv _does…_
|
|
|
|
|
2011-08-18 16:53:48 -04:00
|
|
|
* Let you **change the global Ruby version** on a per-user basis.
|
2011-08-11 15:21:15 -04:00
|
|
|
* 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 `$PATH`.
|
2011-08-14 14:47:07 -04:00
|
|
|
* **Override shell commands like `cd`.** That's dangerous and
|
|
|
|
error-prone.
|
2011-08-11 15:21:15 -04:00
|
|
|
* **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
|
2011-08-11 15:41:24 -04:00
|
|
|
[ruby-build](https://github.com/sstephenson/ruby-build) to
|
2011-08-11 15:21:15 -04:00
|
|
|
automate the process.
|
|
|
|
* **Manage gemsets.** [Bundler](http://gembundler.com/) is a better
|
|
|
|
way to manage application dependencies. If you have projects that
|
|
|
|
are not yet using Bundler you can install the
|
|
|
|
[rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin.
|
|
|
|
* **Require changes to Ruby libraries for compatibility.** The
|
|
|
|
simplicity of rbenv means as long as it's in your `$PATH`,
|
|
|
|
[nothing](https://rvm.beginrescueend.com/integration/bundler/)
|
|
|
|
[else](https://rvm.beginrescueend.com/integration/capistrano/)
|
|
|
|
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."
|
|
|
|
|
2011-08-11 15:25:08 -04:00
|
|
|
## Table of Contents
|
|
|
|
|
2011-08-11 15:21:15 -04:00
|
|
|
## How It Works ##
|
|
|
|
|
|
|
|
rbenv operates on the per-user directory `~/.rbenv`. Version names in
|
|
|
|
rbenv correspond to subdirectories of `~/.rbenv/versions`. For
|
|
|
|
example, you might have `~/.rbenv/versions/1.8.7-p354` and
|
2011-09-28 11:48:04 -04:00
|
|
|
`~/.rbenv/versions/1.9.3-rc1`.
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
|
|
Each version is a working tree with its own binaries, like
|
|
|
|
`~/.rbenv/versions/1.8.7-p354/bin/ruby` and
|
2011-09-28 11:48:04 -04:00
|
|
|
`~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_
|
2011-08-11 15:21:15 -04:00
|
|
|
for every such binary across all installed versions of Ruby.
|
|
|
|
|
|
|
|
These shims are simple wrapper scripts that live in `~/.rbenv/shims`
|
|
|
|
and detect which Ruby version you want to use. They insert the
|
|
|
|
directory for the selected version at the beginning of your `$PATH`
|
|
|
|
and then execute the corresponding binary.
|
|
|
|
|
|
|
|
Because of the simplicity of the shim approach, all you need to use
|
|
|
|
rbenv is `~/.rbenv/shims` in your `$PATH`.
|
|
|
|
|
|
|
|
## Installation ##
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
**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.
|
2011-08-11 15:21:15 -04:00
|
|
|
|
2011-09-28 14:27:42 -04: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 15:21:15 -04:00
|
|
|
|
|
|
|
1. Check out rbenv into `~/.rbenv`.
|
|
|
|
|
|
|
|
$ cd
|
|
|
|
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
|
|
|
|
|
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 15:21:15 -04:00
|
|
|
|
|
|
|
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
**ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`.
|
2011-09-28 11:13:28 -04:00
|
|
|
|
2011-09-28 14:05:29 -04:00
|
|
|
3. Add rbenv init to your shell to enable shims and autocompletion.
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
|
|
$ echo 'eval "$(rbenv init -)"' >> .bash_profile
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
**ZSH note**: Modifiy your `~/.zshrc` file instead of `~/.bash_profile`.
|
|
|
|
|
|
|
|
4. Restart your shell so the path changes take effect. You can now
|
|
|
|
begin using rbenv.
|
2011-08-11 15:21:15 -04:00
|
|
|
|
2011-09-28 11:13:28 -04:00
|
|
|
$ exec $SHELL
|
2011-08-11 15:21:15 -04:00
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
5. Install Ruby versions into `~/.rbenv/versions`. For example, to
|
|
|
|
install Ruby 1.9.2-p290, download and unpack the source, then run:
|
2011-08-11 15:21:15 -04:00
|
|
|
|
2011-08-14 14:47:07 -04:00
|
|
|
$ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290
|
2011-08-11 15:21:15 -04:00
|
|
|
$ make
|
|
|
|
$ make install
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
The [ruby-build](https://github.com/sstephenson/ruby-build)
|
|
|
|
provides an `rbenv install` command that simplifies the process of
|
|
|
|
installing new Ruby versions to:
|
2011-08-11 15:21:15 -04:00
|
|
|
|
2011-09-28 11:13:28 -04:00
|
|
|
$ rbenv install 1.9.2-p290
|
2011-08-11 15:21:15 -04:00
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
6. 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).
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
|
|
$ rbenv rehash
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
#### Upgrading ####
|
2011-09-28 12:20:15 -04:00
|
|
|
|
|
|
|
If you've installed rbenv using the instructions above, you can
|
|
|
|
upgrade your installation at any time using git.
|
|
|
|
|
|
|
|
To upgrade to the latest development version of rbenv, use `git pull`:
|
|
|
|
|
|
|
|
$ cd ~/.rbenv
|
|
|
|
$ git pull
|
|
|
|
|
|
|
|
To upgrade to a specific release of rbenv, check out the corresponding
|
|
|
|
tag:
|
|
|
|
|
|
|
|
$ cd ~/.rbenv
|
|
|
|
$ git fetch
|
|
|
|
$ git tag
|
|
|
|
v0.1.0
|
|
|
|
v0.1.1
|
|
|
|
v0.1.2
|
|
|
|
v0.2.0
|
|
|
|
$ git checkout v0.2.0
|
|
|
|
|
2011-09-28 13:19:36 -04:00
|
|
|
### Homebrew on Mac OS X ###
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
You can also install rbenv using the
|
|
|
|
[Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS
|
|
|
|
X.
|
2011-09-28 13:19:36 -04:00
|
|
|
|
|
|
|
$ brew update
|
|
|
|
$ brew install rbenv
|
2011-09-28 14:05:29 -04:00
|
|
|
$ brew install ruby-build
|
|
|
|
|
|
|
|
The same commands can be used for upgrading.
|
|
|
|
|
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
|
|
|
|
|
|
|
### Neckbeard Configuration ###
|
|
|
|
|
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
|
|
|
|
extra commands into your shell. Coming from rvm, some of you might be
|
|
|
|
opposed to this idea.
|
2011-09-28 14:05:29 -04:00
|
|
|
|
|
|
|
Heres what `rbenv init` actually does:
|
|
|
|
|
2011-09-28 14:27:42 -04:00
|
|
|
1. Sets up your shims path. This is the only requirement for rbenv to
|
|
|
|
functional properly. You can do this by hand by prepending
|
|
|
|
`~/.rbenv/shims` to your `$PATH`.
|
|
|
|
|
|
|
|
2. Installs autocompletion. This is entirely optional but pretty
|
|
|
|
useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that
|
|
|
|
up. There is also a `~/.rbenv/completions/rbenv.zsh` for ZSH
|
|
|
|
users.
|
|
|
|
|
|
|
|
3. Initial rehash. From time to time you'll need to rebuild you're
|
|
|
|
shim files. Doing this on init makes sure everything is up to
|
|
|
|
date. `rbenv rehash` can always be ran manually.
|
|
|
|
|
|
|
|
4. Install sh dispatcher. This bit is also optional but allows rbenv
|
|
|
|
and plugins to change variables in your current shell. This makes
|
|
|
|
commands like `rbenv shell` possible. This doesn't do anything
|
|
|
|
crazy like override `cd` or hack your shell prompt. But for some
|
|
|
|
reason you may need `rbenv` to be a real script rather than a shell
|
|
|
|
function.
|
2011-09-28 13:19:36 -04:00
|
|
|
|
2011-09-28 14:05:29 -04:00
|
|
|
Run `rbenv init -` for yourself to see exactly whats its doing.
|
2011-09-28 13:19:36 -04:00
|
|
|
|
2011-08-11 15:21:15 -04:00
|
|
|
## Usage ##
|
|
|
|
|
|
|
|
Like `git`, the `rbenv` command delegates to subcommands based on its
|
|
|
|
first argument. The most common subcommands are:
|
|
|
|
|
2011-09-28 11:13:28 -04:00
|
|
|
### rbenv global ###
|
2011-08-11 15:21:15 -04:00
|
|
|
|
2011-08-18 16:53:48 -04:00
|
|
|
Sets the global version of Ruby to be used in all shells by writing
|
2011-09-28 11:13:28 -04:00
|
|
|
the version name to the `~/.rbenv/version` file. This version can be
|
2011-08-11 15:21:15 -04:00
|
|
|
overridden by a per-project `.rbenv-version` file, or by setting the
|
|
|
|
`RBENV_VERSION` environment variable.
|
|
|
|
|
2011-08-18 16:53:48 -04:00
|
|
|
$ rbenv global 1.9.2-p290
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
|
|
The special version name `system` tells rbenv to use the system Ruby
|
|
|
|
(detected by searching your `$PATH`).
|
|
|
|
|
2011-08-18 16:53:48 -04:00
|
|
|
When run without a version number, `rbenv global` reports the
|
|
|
|
currently configured global version.
|
|
|
|
|
2011-09-28 11:13:28 -04:00
|
|
|
### rbenv local ###
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
|
|
Sets a local per-project Ruby version by writing the version name to
|
|
|
|
an `.rbenv-version` file in the current directory. This version
|
2011-08-18 16:53:48 -04:00
|
|
|
overrides the global, and can be overridden itself by setting the
|
2011-09-28 11:13:28 -04:00
|
|
|
`RBENV_VERSION` environment variable or with the `rbenv shell`
|
|
|
|
command.
|
2011-08-11 15:21:15 -04:00
|
|
|
|
2011-08-18 16:53:48 -04:00
|
|
|
$ rbenv local rbx-1.2.4
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
### rbenv shell ###
|
|
|
|
|
|
|
|
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
|
|
|
|
environment variable in your shell. This version overrides both
|
|
|
|
project-specific versions and the global version.
|
|
|
|
|
2011-09-28 11:48:04 -04:00
|
|
|
$ rbenv shell jruby-1.6.4
|
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:
|
|
|
|
|
2011-09-28 11:48:04 -04:00
|
|
|
$ export RBENV_VERSION=jruby-1.6.4
|
2011-08-11 15:21:15 -04:00
|
|
|
|
2011-09-28 11:13:28 -04:00
|
|
|
### rbenv versions ###
|
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.
|
|
|
|
|
|
|
|
$ rbenv versions
|
|
|
|
1.8.7-p352
|
|
|
|
1.9.2-p290
|
2011-09-28 11:48:04 -04:00
|
|
|
* 1.9.3-rc1 (set by /Users/sam/.rbenv/global)
|
|
|
|
jruby-1.6.4
|
2011-08-11 15:21:15 -04:00
|
|
|
rbx-1.2.4
|
|
|
|
ree-1.8.7-2011.03
|
|
|
|
|
2011-09-28 11:13:28 -04: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
|
|
|
|
1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version)
|
|
|
|
|
2011-09-28 11:13:28 -04:00
|
|
|
### rbenv rehash ###
|
2011-08-11 15:21:15 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2011-09-28 11:48:04 -04:00
|
|
|
### rbenv which ###
|
|
|
|
|
|
|
|
Displays the full path to the binary that rbenv will execute when you
|
|
|
|
run the given command.
|
|
|
|
|
|
|
|
$ rbenv which irb
|
|
|
|
/Users/sam/.rbenv/versions/1.9.2-p290/bin/irb
|
|
|
|
|
|
|
|
### rbenv whence ###
|
|
|
|
|
|
|
|
Lists all Ruby versions with the given command installed.
|
|
|
|
|
|
|
|
$ rbenv whence rackup
|
|
|
|
1.9.3-rc1
|
|
|
|
jruby-1.6.4
|
|
|
|
ree-1.8.7-2011.03
|
|
|
|
|
2011-09-28 13:01:44 -04:00
|
|
|
## Development ##
|
2011-08-11 15:21:15 -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.
|
|
|
|
|
|
|
|
Please feel free to submit pull requests and file bugs on the [issue
|
|
|
|
tracker](https://github.com/sstephenson/rbenv/issues).
|
|
|
|
|
2011-09-28 13:01:44 -04:00
|
|
|
### Version History ###
|
|
|
|
|
|
|
|
**HEAD**
|
|
|
|
|
|
|
|
* Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local`
|
|
|
|
to `rbenv local`. The `set-` commands are deprecated and will be
|
|
|
|
removed in the next major release.
|
|
|
|
* rbenv now uses `greadlink` on Solaris.
|
|
|
|
* Added a `ruby-local-exec` command which can be used in shebangs in
|
|
|
|
place of `#!/usr/bin/env ruby` to properly set the project-specific
|
|
|
|
Ruby version regardless of current working directory.
|
|
|
|
* Fixed an issue with `rbenv rehash` when no binaries are present.
|
|
|
|
* Added support for `rbenv-sh-*` commands, which run inside the
|
|
|
|
current shell instead of in a child process.
|
|
|
|
* Added an `rbenv shell` command for conveniently setting the
|
|
|
|
`$RBENV_VERSION` environment variable.
|
|
|
|
* Added support for storing rbenv versions and shims in directories
|
|
|
|
other than `~/.rbenv` with the `$RBENV_ROOT` environment variable.
|
|
|
|
* Added support for debugging rbenv via `set -x` when the
|
|
|
|
`$RBENV_DEBUG` environment variable is set.
|
|
|
|
* Refactored the autocompletion system so that completions are now
|
|
|
|
built-in to each command and shared between bash and zsh.
|
|
|
|
* Added support for plugin bundles in `~/.rbenv/plugins` as documented
|
|
|
|
in [issue #102](https://github.com/sstephenson/rbenv/pull/102).
|
|
|
|
* Added `/usr/local/etc/rbenv.d` to the list of directories searched
|
|
|
|
for rbenv hooks.
|
|
|
|
* Added support for an `$RBENV_DIR` environment variable which
|
|
|
|
defaults to the current working directory for specifying where rbenv
|
|
|
|
searches for local version files.
|
|
|
|
|
|
|
|
**0.1.2** (August 16, 2011)
|
|
|
|
|
|
|
|
* Fixed rbenv to be more resilient against nonexistent entries in
|
|
|
|
`$PATH`.
|
|
|
|
* Made the `rbenv rehash` command operate atomically.
|
|
|
|
* Modified the `rbenv init` script to automatically run `rbenv
|
|
|
|
rehash` so that shims are recreated whenever a new shell is opened.
|
|
|
|
* Added initial support for zsh autocompletion.
|
|
|
|
* Removed the dependency on egrep for reading version files.
|
|
|
|
|
|
|
|
**0.1.1** (August 14, 2011)
|
|
|
|
|
|
|
|
* Fixed a syntax error in the `rbenv help` command.
|
|
|
|
* Removed `-e` from the shebang in favor of `set -e` at the top of
|
|
|
|
each file for compatibility with operating systems that do not
|
|
|
|
support more than one argument in the shebang.
|
|
|
|
|
|
|
|
**0.1.0** (August 11, 2011)
|
|
|
|
|
|
|
|
* Initial public release.
|
|
|
|
|
2011-08-11 15:21:15 -04:00
|
|
|
### License ###
|
|
|
|
|
|
|
|
(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.
|