pyenv/README.md

443 lines
15 KiB
Markdown
Raw Normal View History

2013-01-03 13:49:03 -05:00
# Groom your apps 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
with [Bundler](http://gembundler.com/) for painless Ruby upgrades and
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
binstubs](http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/)
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
use the [ruby-build](https://github.com/sstephenson/ruby-build)
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
2011-08-11 15:25:08 -04:00
## Table of Contents
* [How It Works](#how-it-works)
* [Installation](#installation)
* [Basic GitHub Checkout](#basic-github-checkout)
* [Upgrading](#upgrading)
* [Homebrew on Mac OS X](#homebrew-on-mac-os-x)
* [Neckbeard Configuration](#neckbeard-configuration)
* [Uninstalling Ruby Versions](#uninstalling-ruby-versions)
2013-01-03 11:25:31 -05:00
* [Command Reference](#command-reference)
* [rbenv local](#rbenv-local)
* [rbenv global](#rbenv-global)
* [rbenv shell](#rbenv-shell)
* [rbenv versions](#rbenv-versions)
* [rbenv version](#rbenv-version)
* [rbenv rehash](#rbenv-rehash)
* [rbenv which](#rbenv-which)
* [rbenv whence](#rbenv-whence)
* [Development](#development)
* [Version History](#version-history)
* [License](#license)
## How It Works ##
2011-08-11 13:51:35 -04:00
2011-08-11 14:11:37 -04:00
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
`~/.rbenv/versions/1.9.3-p327`.
2011-08-11 13:51:35 -04:00
2013-01-03 11:06:12 -05:00
Each version is a working tree with its own executables, like
2011-08-11 14:11:37 -04:00
`~/.rbenv/versions/1.8.7-p354/bin/ruby` and
2013-01-03 11:06:12 -05:00
`~/.rbenv/versions/1.9.3-p327/bin/irb`. rbenv makes _shim executables_
for every such executable across all installed versions of Ruby.
2011-08-11 13:51:35 -04:00
2011-08-11 14:11:37 -04:00
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`
2013-01-03 11:06:12 -05:00
and then invoke the corresponding executable.
2011-08-11 13:51:35 -04:00
## Installation ##
2011-08-11 13:51:35 -04: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
If you're on Mac OS X, consider
[installing with Homebrew](#homebrew-on-mac-os-x).
### 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`.
~~~ sh
$ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
~~~
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
~~~ sh
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
~~~
2011-08-11 13:51:35 -04:00
2012-01-29 04:25:14 -05:00
**Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`.
2011-09-28 11:13:28 -04:00
2013-01-02 19:56:23 -05:00
**Ubuntu note**: Ubuntu uses `~/.profile` for enabling certain path
changes. This file won't be read if you create a `~/.bash_profile`.
Therefore, it's recommended that you add this line and the one in
point 3 below to your `~/.profile`. This has the added advantage
of working under both bash and zsh.
3. Add `rbenv init` to your shell to enable shims and autocompletion.
2011-08-11 13:51:35 -04:00
~~~ sh
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
~~~
2011-08-11 13:51:35 -04:00
2012-01-29 04:25:14 -05:00
**Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`.
2013-01-02 19:56:23 -05:00
**Ubuntu note**: Same as Ubuntu note for point 2 above.
2011-09-28 14:27:42 -04:00
2013-01-02 19:56:23 -05:00
4. Restart your shell as a login shell so the path changes take effect.
You can now begin using rbenv.
2011-08-11 13:51:35 -04:00
~~~ sh
$ exec $SHELL -l
~~~
2011-08-11 13:51:35 -04:00
2013-01-02 19:56:23 -05:00
5. Install [ruby-build](https://github.com/sstephenson/ruby-build),
which provides an `rbenv install` command that simplifies the
process of installing new Ruby versions.
2011-08-11 13:51:35 -04:00
~~~
$ rbenv install 1.9.3-p327
~~~
2011-08-11 13:51:35 -04:00
2012-12-14 11:42:10 -05:00
As an alternative, you can download and compile Ruby yourself into
`~/.rbenv/versions/`.
2013-01-03 11:06:12 -05:00
6. Rebuild the shim executables. You should do this any time you
install a new Ruby executable (for example, when installing a new
Ruby version, or when installing a gem that provides a command).
2011-08-11 13:51:35 -04:00
~~~
$ rbenv rehash
~~~
2011-08-11 13:51:35 -04:00
#### Upgrading ####
2011-09-28 12:20:36 -04: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
~~~ sh
$ cd ~/.rbenv
$ git pull
~~~
2011-09-28 12:20:36 -04:00
To use a specific release of rbenv, check out the corresponding tag:
2011-09-28 12:20:36 -04:00
~~~ sh
$ 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 12:20:36 -04:00
### Homebrew on Mac OS X ###
2011-09-28 13:19:36 -04:00
2013-01-02 19:56:23 -05: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
$ brew install ruby-build
~~~
2011-09-28 14:05:29 -04:00
To later update these installs, use `upgrade` instead of `install`.
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
### Neckbeard Configuration ###
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
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
2011-09-28 14:27:42 -04:00
shim files. Doing this on init 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
### Uninstalling Ruby Versions ###
2013-01-03 11:20:52 -05:00
As time goes on, Ruby versions you install will accumulate in your
`~/.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
Ruby verison with the `rbenv prefix` command, e.g. `rbenv prefix
1.8.7-p357`.
The [ruby-build](https://github.com/sstephenson/ruby-build) plugin
provides an `rbenv uninstall` command to automate the removal
process.
2013-01-03 11:25:31 -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
### rbenv local ###
2011-08-11 13:51:35 -04:00
Sets a local application-specific Ruby version by writing the version
name to a `.ruby-version` file in the current directory. This version
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
$ 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.
### rbenv global ###
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.
### rbenv shell ###
2011-09-28 11:13:28 -04:00
Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
environment variable in your shell. This version overrides
application-specific versions and the global version.
2011-09-28 11:13:28 -04: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:
$ export RBENV_VERSION=jruby-1.7.1
2011-08-11 13:51:35 -04: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)
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
### 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
2012-12-31 10:58:28 -05:00
1.8.7-p352 (set by /Volumes/37signals/basecamp/.ruby-version)
2011-08-11 15:21:15 -04: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
### rbenv which ###
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.
$ rbenv which irb
/Users/sam/.rbenv/versions/1.9.3-p327/bin/irb
### rbenv whence ###
Lists all Ruby versions with the given command installed.
$ rbenv whence rackup
1.9.3-p327
jruby-1.7.1
ree-1.8.7-2011.03
## 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
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
### Version History ###
2011-09-28 13:01:44 -04:00
2011-12-25 21:32:48 -05:00
**0.3.0** (December 25, 2011)
* Added an `rbenv root` command which prints the value of
`$RBENV_ROOT`, or the default root directory if it's unset.
* Clarified Zsh installation instructions in the readme.
* Removed some redundant code in `rbenv rehash`.
* Fixed an issue with calling `readlink` for paths with spaces.
* Changed Zsh initialization code to install completion hooks only for
interactive shells.
* Added preliminary support for ksh.
* `rbenv rehash` creates or removes shims only when necessary instead
of removing and re-creating all shims on each invocation.
* Fixed that `RBENV_DIR`, when specified, would be incorrectly
expanded to its parent directory.
* Removed the deprecated `set-default` and `set-local` commands.
* Added a `--no-rehash` option to `rbenv init` for skipping the
automatic rehash when opening a new shell.
2011-10-01 13:26:19 -04:00
**0.2.1** (October 1, 2011)
* Changed the `rbenv` command to ensure that `RBENV_DIR` is always an
absolute path. This fixes an issue where Ruby scripts using the
`ruby-local-exec` wrapper would go into an infinite loop when
invoked with a relative path from the command line.
2011-09-28 14:38:03 -04:00
**0.2.0** (September 28, 2011)
2011-09-28 13:01:44 -04:00
* 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
2011-09-28 14:29:37 -04:00
built-in to each command and shared between bash and Zsh.
2011-09-28 13:01:44 -04:00
* 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.
2011-09-28 14:29:37 -04:00
* Added initial support for Zsh autocompletion.
2011-09-28 13:01:44 -04:00
* 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.
### License ###
2011-08-11 13:51:35 -04:00
(The MIT license)
2013-01-02 19:56:23 -05:00
Copyright (c) 2013 Sam Stephenson
2011-08-11 13:51:35 -04:00
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
2011-08-11 13:53:20 -04:00
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.