No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

480 líneas
16 KiB

hace 13 años
hace 8 años
hace 8 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 11 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 11 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 8 años
hace 8 años
hace 8 años
hace 11 años
hace 13 años
hace 13 años
hace 13 años
hace 11 años
hace 13 años
  1. # Groom your app’s Ruby environment with rbenv.
  2. Use rbenv to pick a Ruby version for your application and guarantee
  3. that your development environment matches production. Put rbenv to work
  4. with [Bundler](http://bundler.io/) for painless Ruby upgrades and
  5. bulletproof deployments.
  6. **Powerful in development.** Specify your app's Ruby version once,
  7. in a single file. Keep all your teammates on the same page. No
  8. headaches running apps on different versions of Ruby. Just Works™
  9. from the command line and with app servers like [Pow](http://pow.cx).
  10. Override the Ruby version anytime: just set an environment variable.
  11. **Rock-solid in production.** Your application's executables are its
  12. interface with ops. With rbenv and [Bundler
  13. binstubs](https://github.com/rbenv/rbenv/wiki/Understanding-binstubs)
  14. you'll never again need to `cd` in a cron job or Chef recipe to
  15. ensure you've selected the right runtime. The Ruby version
  16. dependency lives in one place—your app—so upgrades and rollbacks are
  17. atomic, even when you switch versions.
  18. **One thing well.** rbenv is concerned solely with switching Ruby
  19. versions. It's simple and predictable. A rich plugin ecosystem lets
  20. you tailor it to suit your needs. Compile your own Ruby versions, or
  21. use the [ruby-build][]
  22. plugin to automate the process. Specify per-application environment
  23. variables with [rbenv-vars](https://github.com/rbenv/rbenv-vars).
  24. See more [plugins on the
  25. wiki](https://github.com/rbenv/rbenv/wiki/Plugins).
  26. [**Why choose rbenv over
  27. RVM?**](https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F)
  28. ## Table of Contents
  29. * [How It Works](#how-it-works)
  30. * [Understanding PATH](#understanding-path)
  31. * [Understanding Shims](#understanding-shims)
  32. * [Choosing the Ruby Version](#choosing-the-ruby-version)
  33. * [Locating the Ruby Installation](#locating-the-ruby-installation)
  34. * [Installation](#installation)
  35. * [Basic GitHub Checkout](#basic-github-checkout)
  36. * [Upgrading](#upgrading)
  37. * [Homebrew on Mac OS X](#homebrew-on-mac-os-x)
  38. * [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell)
  39. * [Installing Ruby versions](#installing-ruby-versions)
  40. * [Installing Ruby gems](#installing-ruby-gems)
  41. * [Uninstalling Ruby versions](#uninstalling-ruby-versions)
  42. * [Uninstalling rbenv](#uninstalling-rbenv)
  43. * [Command Reference](#command-reference)
  44. * [rbenv local](#rbenv-local)
  45. * [rbenv global](#rbenv-global)
  46. * [rbenv shell](#rbenv-shell)
  47. * [rbenv versions](#rbenv-versions)
  48. * [rbenv version](#rbenv-version)
  49. * [rbenv rehash](#rbenv-rehash)
  50. * [rbenv which](#rbenv-which)
  51. * [rbenv whence](#rbenv-whence)
  52. * [Environment variables](#environment-variables)
  53. * [Development](#development)
  54. ## How It Works
  55. At a high level, rbenv intercepts Ruby commands using shim
  56. executables injected into your `PATH`, determines which Ruby version
  57. has been specified by your application, and passes your commands along
  58. to the correct Ruby installation.
  59. ### Understanding PATH
  60. When you run a command like `ruby` or `rake`, your operating system
  61. searches through a list of directories to find an executable file with
  62. that name. This list of directories lives in an environment variable
  63. called `PATH`, with each directory in the list separated by a colon:
  64. /usr/local/bin:/usr/bin:/bin
  65. Directories in `PATH` are searched from left to right, so a matching
  66. executable in a directory at the beginning of the list takes
  67. precedence over another one at the end. In this example, the
  68. `/usr/local/bin` directory will be searched first, then `/usr/bin`,
  69. then `/bin`.
  70. ### Understanding Shims
  71. rbenv works by inserting a directory of _shims_ at the front of your
  72. `PATH`:
  73. ~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin
  74. Through a process called _rehashing_, rbenv maintains shims in that
  75. directory to match every Ruby command across every installed version
  76. of Ruby—`irb`, `gem`, `rake`, `rails`, `ruby`, and so on.
  77. Shims are lightweight executables that simply pass your command along
  78. to rbenv. So with rbenv installed, when you run, say, `rake`, your
  79. operating system will do the following:
  80. * Search your `PATH` for an executable file named `rake`
  81. * Find the rbenv shim named `rake` at the beginning of your `PATH`
  82. * Run the shim named `rake`, which in turn passes the command along to
  83. rbenv
  84. ### Choosing the Ruby Version
  85. When you execute a shim, rbenv determines which Ruby version to use by
  86. reading it from the following sources, in this order:
  87. 1. The `RBENV_VERSION` environment variable, if specified. You can use
  88. the [`rbenv shell`](#rbenv-shell) command to set this environment
  89. variable in your current shell session.
  90. 2. The first `.ruby-version` file found by searching the directory of the
  91. script you are executing and each of its parent directories until reaching
  92. the root of your filesystem.
  93. 3. The first `.ruby-version` file found by searching the current working
  94. directory and each of its parent directories until reaching the root of your
  95. filesystem. You can modify the `.ruby-version` file in the current working
  96. directory with the [`rbenv local`](#rbenv-local) command.
  97. 4. The global `~/.rbenv/version` file. You can modify this file using
  98. the [`rbenv global`](#rbenv-global) command. If the global version
  99. file is not present, rbenv assumes you want to use the "system"
  100. Ruby—i.e. whatever version would be run if rbenv weren't in your
  101. path.
  102. ### Locating the Ruby Installation
  103. Once rbenv has determined which version of Ruby your application has
  104. specified, it passes the command along to the corresponding Ruby
  105. installation.
  106. Each Ruby version is installed into its own directory under
  107. `~/.rbenv/versions`. For example, you might have these versions
  108. installed:
  109. * `~/.rbenv/versions/1.8.7-p371/`
  110. * `~/.rbenv/versions/1.9.3-p327/`
  111. * `~/.rbenv/versions/jruby-1.7.1/`
  112. Version names to rbenv are simply the names of the directories in
  113. `~/.rbenv/versions`.
  114. ## Installation
  115. **Compatibility note**: rbenv is _incompatible_ with RVM. Please make
  116. sure to fully uninstall RVM and remove any references to it from
  117. your shell initialization files before installing rbenv.
  118. If you're on Mac OS X, consider
  119. [installing with Homebrew](#homebrew-on-mac-os-x).
  120. ### Basic GitHub Checkout
  121. This will get you going with the latest version of rbenv and make it
  122. easy to fork and contribute any changes back upstream.
  123. 1. Check out rbenv into `~/.rbenv`.
  124. ~~~ sh
  125. $ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
  126. ~~~
  127. Optionally, try to compile dynamic bash extension to speed up rbenv. Don't
  128. worry if it fails; rbenv will still work normally:
  129. ~~~
  130. $ cd ~/.rbenv && src/configure && make -C src
  131. ~~~
  132. 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
  133. command-line utility.
  134. ~~~ sh
  135. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
  136. ~~~
  137. **Ubuntu Desktop note**: Modify your `~/.bashrc` instead of `~/.bash_profile`.
  138. **Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`.
  139. 3. Run `~/.rbenv/bin/rbenv init` for shell-specific instructions on how to
  140. initialize rbenv to enable shims and autocompletion.
  141. 4. Restart your shell so that PATH changes take effect. (Opening a new
  142. terminal tab will usually do it.) Now check if rbenv was set up:
  143. ~~~ sh
  144. $ type rbenv
  145. #=> "rbenv is a function"
  146. ~~~
  147. 5. _(Optional)_ Install [ruby-build][], which provides the
  148. `rbenv install` command that simplifies the process of
  149. [installing new Ruby versions](#installing-ruby-versions).
  150. #### Upgrading
  151. If you've installed rbenv manually using git, you can upgrade your
  152. installation to the cutting-edge version at any time.
  153. ~~~ sh
  154. $ cd ~/.rbenv
  155. $ git pull
  156. ~~~
  157. To use a specific release of rbenv, check out the corresponding tag:
  158. ~~~ sh
  159. $ cd ~/.rbenv
  160. $ git fetch
  161. $ git checkout v0.3.0
  162. ~~~
  163. If you've [installed via Homebrew](#homebrew-on-mac-os-x), then upgrade
  164. via its `brew` command:
  165. ~~~ sh
  166. $ brew update
  167. $ brew upgrade rbenv ruby-build
  168. ~~~
  169. ### Homebrew on Mac OS X
  170. As an alternative to installation via GitHub checkout, you can install
  171. rbenv and [ruby-build][] using the [Homebrew](http://brew.sh) package
  172. manager on Mac OS X:
  173. ~~~
  174. $ brew update
  175. $ brew install rbenv
  176. $ rbenv init
  177. ~~~
  178. You'll only ever have to run `rbenv init` once.
  179. ### How rbenv hooks into your shell
  180. Skip this section unless you must know what every line in your shell
  181. profile is doing.
  182. `rbenv init` is the only command that crosses the line of loading
  183. extra commands into your shell. Coming from RVM, some of you might be
  184. opposed to this idea. Here's what `rbenv init` actually does:
  185. 1. Sets up your shims path. This is the only requirement for rbenv to
  186. function properly. You can do this by hand by prepending
  187. `~/.rbenv/shims` to your `$PATH`.
  188. 2. Installs autocompletion. This is entirely optional but pretty
  189. useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that
  190. up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh
  191. users.
  192. 3. Rehashes shims. From time to time you'll need to rebuild your
  193. shim files. Doing this automatically makes sure everything is up to
  194. date. You can always run `rbenv rehash` manually.
  195. 4. Installs the sh dispatcher. This bit is also optional, but allows
  196. rbenv and plugins to change variables in your current shell, making
  197. commands like `rbenv shell` possible. The sh dispatcher doesn't do
  198. anything crazy like override `cd` or hack your shell prompt, but if
  199. for some reason you need `rbenv` to be a real script rather than a
  200. shell function, you can safely skip it.
  201. Run `rbenv init -` for yourself to see exactly what happens under the
  202. hood.
  203. ### Installing Ruby versions
  204. The `rbenv install` command doesn't ship with rbenv out of the box, but
  205. is provided by the [ruby-build][] project. If you installed it either
  206. as part of GitHub checkout process outlined above or via Homebrew, you
  207. should be able to:
  208. ~~~ sh
  209. # list all available versions:
  210. $ rbenv install -l
  211. # install a Ruby version:
  212. $ rbenv install 2.0.0-p247
  213. ~~~
  214. Alternatively to the `install` command, you can download and compile
  215. Ruby manually as a subdirectory of `~/.rbenv/versions/`. An entry in
  216. that directory can also be a symlink to a Ruby version installed
  217. elsewhere on the filesystem. rbenv doesn't care; it will simply treat
  218. any entry in the `versions/` directory as a separate Ruby version.
  219. #### Installing Ruby gems
  220. Once you've installed some Ruby versions, you'll want to install gems.
  221. First, ensure that the target version for your project is the one you want by
  222. checking `rbenv version` (see [Command Reference](#command-reference)). Select
  223. another version using `rbenv local 2.0.0-p247`, for example. Then, proceed to
  224. install gems as you normally would:
  225. ```sh
  226. $ gem install bundler
  227. ```
  228. **You don't need sudo** to install gems. Typically, the Ruby versions will be
  229. installed and writeable by your user. No extra privileges are required to
  230. install gems.
  231. Check the location where gems are being installed with `gem env`:
  232. ```sh
  233. $ gem env home
  234. # => ~/.rbenv/versions/<ruby-version>/lib/ruby/gems/...
  235. ```
  236. ### Uninstalling Ruby versions
  237. As time goes on, Ruby versions you install will accumulate in your
  238. `~/.rbenv/versions` directory.
  239. To remove old Ruby versions, simply `rm -rf` the directory of the
  240. version you want to remove. You can find the directory of a particular
  241. Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix
  242. 1.8.7-p357`.
  243. The [ruby-build][] plugin provides an `rbenv uninstall` command to
  244. automate the removal process.
  245. ### Uninstalling rbenv
  246. The simplicity of rbenv makes it easy to temporarily disable it, or
  247. uninstall from the system.
  248. 1. To **disable** rbenv managing your Ruby versions, simply remove the
  249. `rbenv init` line from your shell startup configuration. This will
  250. remove rbenv shims directory from PATH, and future invocations like
  251. `ruby` will execute the system Ruby version, as before rbenv.
  252. `rbenv` will still be accessible on the command line, but your Ruby
  253. apps won't be affected by version switching.
  254. 2. To completely **uninstall** rbenv, perform step (1) and then remove
  255. its root directory. This will **delete all Ruby versions** that were
  256. installed under `` `rbenv root`/versions/ `` directory:
  257. rm -rf `rbenv root`
  258. If you've installed rbenv using a package manager, as a final step
  259. perform the rbenv package removal. For instance, for Homebrew:
  260. brew uninstall rbenv
  261. ## Command Reference
  262. Like `git`, the `rbenv` command delegates to subcommands based on its
  263. first argument. The most common subcommands are:
  264. ### rbenv local
  265. Sets a local application-specific Ruby version by writing the version
  266. name to a `.ruby-version` file in the current directory. This version
  267. overrides the global version, and can be overridden itself by setting
  268. the `RBENV_VERSION` environment variable or with the `rbenv shell`
  269. command.
  270. $ rbenv local 1.9.3-p327
  271. When run without a version number, `rbenv local` reports the currently
  272. configured local version. You can also unset the local version:
  273. $ rbenv local --unset
  274. ### rbenv global
  275. Sets the global version of Ruby to be used in all shells by writing
  276. the version name to the `~/.rbenv/version` file. This version can be
  277. overridden by an application-specific `.ruby-version` file, or by
  278. setting the `RBENV_VERSION` environment variable.
  279. $ rbenv global 1.8.7-p352
  280. The special version name `system` tells rbenv to use the system Ruby
  281. (detected by searching your `$PATH`).
  282. When run without a version number, `rbenv global` reports the
  283. currently configured global version.
  284. ### rbenv shell
  285. Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
  286. environment variable in your shell. This version overrides
  287. application-specific versions and the global version.
  288. $ rbenv shell jruby-1.7.1
  289. When run without a version number, `rbenv shell` reports the current
  290. value of `RBENV_VERSION`. You can also unset the shell version:
  291. $ rbenv shell --unset
  292. Note that you'll need rbenv's shell integration enabled (step 3 of
  293. the installation instructions) in order to use this command. If you
  294. prefer not to use shell integration, you may simply set the
  295. `RBENV_VERSION` variable yourself:
  296. $ export RBENV_VERSION=jruby-1.7.1
  297. ### rbenv versions
  298. Lists all Ruby versions known to rbenv, and shows an asterisk next to
  299. the currently active version.
  300. $ rbenv versions
  301. 1.8.7-p352
  302. 1.9.2-p290
  303. * 1.9.3-p327 (set by /Users/sam/.rbenv/version)
  304. jruby-1.7.1
  305. rbx-1.2.4
  306. ree-1.8.7-2011.03
  307. ### rbenv version
  308. Displays the currently active Ruby version, along with information on
  309. how it was set.
  310. $ rbenv version
  311. 1.9.3-p327 (set by /Users/sam/.rbenv/version)
  312. ### rbenv rehash
  313. Installs shims for all Ruby executables known to rbenv (i.e.,
  314. `~/.rbenv/versions/*/bin/*`). Run this command after you install a new
  315. version of Ruby, or install a gem that provides commands.
  316. $ rbenv rehash
  317. ### rbenv which
  318. Displays the full path to the executable that rbenv will invoke when
  319. you run the given command.
  320. $ rbenv which irb
  321. /Users/sam/.rbenv/versions/1.9.3-p327/bin/irb
  322. ### rbenv whence
  323. Lists all Ruby versions with the given command installed.
  324. $ rbenv whence rackup
  325. 1.9.3-p327
  326. jruby-1.7.1
  327. ree-1.8.7-2011.03
  328. ## Environment variables
  329. You can affect how rbenv operates with the following settings:
  330. name | default | description
  331. -----|---------|------------
  332. `RBENV_VERSION` | | Specifies the Ruby version to be used.<br>Also see [`rbenv shell`](#rbenv-shell)
  333. `RBENV_ROOT` | `~/.rbenv` | Defines the directory under which Ruby versions and shims reside.<br>Also see `rbenv root`
  334. `RBENV_DEBUG` | | Outputs debug information.<br>Also as: `rbenv --debug <subcommand>`
  335. `RBENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for rbenv hooks.
  336. `RBENV_DIR` | `$PWD` | Directory to start searching for `.ruby-version` files.
  337. ## Development
  338. The rbenv source code is [hosted on
  339. GitHub](https://github.com/rbenv/rbenv). It's clean, modular,
  340. and easy to understand, even if you're not a shell hacker.
  341. Tests are executed using [Bats](https://github.com/sstephenson/bats):
  342. $ bats test
  343. $ bats test/<file>.bats
  344. Please feel free to submit pull requests and file bugs on the [issue
  345. tracker](https://github.com/rbenv/rbenv/issues).
  346. [ruby-build]: https://github.com/rbenv/ruby-build#readme
  347. [hooks]: https://github.com/rbenv/rbenv/wiki/Authoring-plugins#rbenv-hooks