Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

574 linhas
21 KiB

13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
11 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
11 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
11 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
11 anos atrás
13 anos atrás
13 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
12 anos atrás
11 anos atrás
12 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
  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://gembundler.com/) 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/sstephenson/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/sstephenson/rbenv-vars).
  24. See more [plugins on the
  25. wiki](https://github.com/sstephenson/rbenv/wiki/Plugins).
  26. [**Why choose rbenv over
  27. RVM?**](https://github.com/sstephenson/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. * [Uninstalling Ruby Versions](#uninstalling-ruby-versions)
  41. * [Command Reference](#command-reference)
  42. * [rbenv local](#rbenv-local)
  43. * [rbenv global](#rbenv-global)
  44. * [rbenv shell](#rbenv-shell)
  45. * [rbenv versions](#rbenv-versions)
  46. * [rbenv version](#rbenv-version)
  47. * [rbenv rehash](#rbenv-rehash)
  48. * [rbenv which](#rbenv-which)
  49. * [rbenv whence](#rbenv-whence)
  50. * [Development](#development)
  51. * [Version History](#version-history)
  52. * [License](#license)
  53. ## How It Works
  54. At a high level, rbenv intercepts Ruby commands using shim
  55. executables injected into your `PATH`, determines which Ruby version
  56. has been specified by your application, and passes your commands along
  57. to the correct Ruby installation.
  58. ### Understanding PATH
  59. When you run a command like `ruby` or `rake`, your operating system
  60. searches through a list of directories to find an executable file with
  61. that name. This list of directories lives in an environment variable
  62. called `PATH`, with each directory in the list separated by a colon:
  63. /usr/local/bin:/usr/bin:/bin
  64. Directories in `PATH` are searched from left to right, so a matching
  65. executable in a directory at the beginning of the list takes
  66. precedence over another one at the end. In this example, the
  67. `/usr/local/bin` directory will be searched first, then `/usr/bin`,
  68. then `/bin`.
  69. ### Understanding Shims
  70. rbenv works by inserting a directory of _shims_ at the front of your
  71. `PATH`:
  72. ~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin
  73. Through a process called _rehashing_, rbenv maintains shims in that
  74. directory to match every Ruby command across every installed version
  75. of Ruby—`irb`, `gem`, `rake`, `rails`, `ruby`, and so on.
  76. Shims are lightweight executables that simply pass your command along
  77. to rbenv. So with rbenv installed, when you run, say, `rake`, your
  78. operating system will do the following:
  79. * Search your `PATH` for an executable file named `rake`
  80. * Find the rbenv shim named `rake` at the beginning of your `PATH`
  81. * Run the shim named `rake`, which in turn passes the command along to
  82. rbenv
  83. ### Choosing the Ruby Version
  84. When you execute a shim, rbenv determines which Ruby version to use by
  85. reading it from the following sources, in this order:
  86. 1. The `RBENV_VERSION` environment variable, if specified. You can use
  87. the [`rbenv shell`](#rbenv-shell) command to set this environment
  88. variable in your current shell session.
  89. 2. The first `.ruby-version` file found by searching the directory of the
  90. script you are executing and each of its parent directories until reaching
  91. the root of your filesystem.
  92. 3. The first `.ruby-version` file found by searching the current working
  93. directory and each of its parent directories until reaching the root of your
  94. filesystem. You can modify the `.ruby-version` file in the current working
  95. directory with the [`rbenv local`](#rbenv-local) command.
  96. 4. The global `~/.rbenv/version` file. You can modify this file using
  97. the [`rbenv global`](#rbenv-global) command. If the global version
  98. file is not present, rbenv assumes you want to use the "system"
  99. Ruby—i.e. whatever version would be run if rbenv weren't in your
  100. path.
  101. ### Locating the Ruby Installation
  102. Once rbenv has determined which version of Ruby your application has
  103. specified, it passes the command along to the corresponding Ruby
  104. installation.
  105. Each Ruby version is installed into its own directory under
  106. `~/.rbenv/versions`. For example, you might have these versions
  107. installed:
  108. * `~/.rbenv/versions/1.8.7-p371/`
  109. * `~/.rbenv/versions/1.9.3-p327/`
  110. * `~/.rbenv/versions/jruby-1.7.1/`
  111. Version names to rbenv are simply the names of the directories in
  112. `~/.rbenv/versions`.
  113. ## Installation
  114. **Compatibility note**: rbenv is _incompatible_ with RVM. Please make
  115. sure to fully uninstall RVM and remove any references to it from
  116. your shell initialization files before installing rbenv.
  117. If you're on Mac OS X, consider
  118. [installing with Homebrew](#homebrew-on-mac-os-x).
  119. ### Basic GitHub Checkout
  120. This will get you going with the latest version of rbenv and make it
  121. easy to fork and contribute any changes back upstream.
  122. 1. Check out rbenv into `~/.rbenv`.
  123. ~~~ sh
  124. $ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
  125. ~~~
  126. 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
  127. command-line utility.
  128. ~~~ sh
  129. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
  130. ~~~
  131. **Ubuntu Desktop note**: Modify your `~/.bashrc` instead of `~/.bash_profile`.
  132. **Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`.
  133. 3. Add `rbenv init` to your shell to enable shims and autocompletion.
  134. ~~~ sh
  135. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
  136. ~~~
  137. _Same as in previous step, use `~/.bashrc` on Ubuntu, or `~/.zshrc` for Zsh._
  138. 4. Restart your shell so that PATH changes take effect. (Opening a new
  139. terminal tab will usually do it.) Now check if rbenv was set up:
  140. ~~~ sh
  141. $ type rbenv
  142. #=> "rbenv is a function"
  143. ~~~
  144. 5. _(Optional)_ Install [ruby-build][], which provides the
  145. `rbenv install` command that simplifies the process of
  146. [installing new Ruby versions](#installing-ruby-versions).
  147. #### Upgrading
  148. If you've installed rbenv manually using git, you can upgrade your
  149. installation to the cutting-edge version at any time.
  150. ~~~ sh
  151. $ cd ~/.rbenv
  152. $ git pull
  153. ~~~
  154. To use a specific release of rbenv, check out the corresponding tag:
  155. ~~~ sh
  156. $ cd ~/.rbenv
  157. $ git fetch
  158. $ git checkout v0.3.0
  159. ~~~
  160. If you've [installed via Homebrew](#homebrew-on-mac-os-x), then upgrade
  161. via its `brew` command:
  162. ~~~ sh
  163. $ brew update
  164. $ brew upgrade rbenv ruby-build
  165. ~~~
  166. ### Homebrew on Mac OS X
  167. As an alternative to installation via GitHub checkout, you can install
  168. rbenv and [ruby-build][] using the [Homebrew](http://brew.sh) package
  169. manager on Mac OS X:
  170. ~~~
  171. $ brew update
  172. $ brew install rbenv ruby-build
  173. ~~~
  174. Afterwards you'll still need to add `eval "$(rbenv init -)"` to your
  175. profile as stated in the caveats. You'll only ever have to do this
  176. once.
  177. ### How rbenv hooks into your shell
  178. Skip this section unless you must know what every line in your shell
  179. profile is doing.
  180. `rbenv init` is the only command that crosses the line of loading
  181. extra commands into your shell. Coming from RVM, some of you might be
  182. opposed to this idea. Here's what `rbenv init` actually does:
  183. 1. Sets up your shims path. This is the only requirement for rbenv to
  184. function properly. You can do this by hand by prepending
  185. `~/.rbenv/shims` to your `$PATH`.
  186. 2. Installs autocompletion. This is entirely optional but pretty
  187. useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that
  188. up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh
  189. users.
  190. 3. Rehashes shims. From time to time you'll need to rebuild your
  191. shim files. Doing this automatically makes sure everything is up to
  192. date. You can always run `rbenv rehash` manually.
  193. 4. Installs the sh dispatcher. This bit is also optional, but allows
  194. rbenv and plugins to change variables in your current shell, making
  195. commands like `rbenv shell` possible. The sh dispatcher doesn't do
  196. anything crazy like override `cd` or hack your shell prompt, but if
  197. for some reason you need `rbenv` to be a real script rather than a
  198. shell function, you can safely skip it.
  199. Run `rbenv init -` for yourself to see exactly what happens under the
  200. hood.
  201. ### Installing Ruby Versions
  202. The `rbenv install` command doesn't ship with rbenv out of the box, but
  203. is provided by the [ruby-build][] project. If you installed it either
  204. as part of GitHub checkout process outlined above or via Homebrew, you
  205. should be able to:
  206. ~~~ sh
  207. # list all available versions:
  208. $ rbenv install -l
  209. # install a Ruby version:
  210. $ rbenv install 2.0.0-p247
  211. ~~~
  212. Alternatively to the `install` command, you can download and compile
  213. Ruby manually as a subdirectory of `~/.rbenv/versions/`. An entry in
  214. that directory can also be a symlink to a Ruby version installed
  215. elsewhere on the filesystem. rbenv doesn't care; it will simply treat
  216. any entry in the `versions/` directory as a separate Ruby version.
  217. ### Uninstalling Ruby Versions
  218. As time goes on, Ruby versions you install will accumulate in your
  219. `~/.rbenv/versions` directory.
  220. To remove old Ruby versions, simply `rm -rf` the directory of the
  221. version you want to remove. You can find the directory of a particular
  222. Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix
  223. 1.8.7-p357`.
  224. The [ruby-build][] plugin provides an `rbenv uninstall` command to
  225. automate the removal process.
  226. ## Command Reference
  227. Like `git`, the `rbenv` command delegates to subcommands based on its
  228. first argument. The most common subcommands are:
  229. ### rbenv local
  230. Sets a local application-specific Ruby version by writing the version
  231. name to a `.ruby-version` file in the current directory. This version
  232. overrides the global version, and can be overridden itself by setting
  233. the `RBENV_VERSION` environment variable or with the `rbenv shell`
  234. command.
  235. $ rbenv local 1.9.3-p327
  236. When run without a version number, `rbenv local` reports the currently
  237. configured local version. You can also unset the local version:
  238. $ rbenv local --unset
  239. Previous versions of rbenv stored local version specifications in a
  240. file named `.rbenv-version`. For backwards compatibility, rbenv will
  241. read a local version specified in an `.rbenv-version` file, but a
  242. `.ruby-version` file in the same directory will take precedence.
  243. ### rbenv global
  244. Sets the global version of Ruby to be used in all shells by writing
  245. the version name to the `~/.rbenv/version` file. This version can be
  246. overridden by an application-specific `.ruby-version` file, or by
  247. setting the `RBENV_VERSION` environment variable.
  248. $ rbenv global 1.8.7-p352
  249. The special version name `system` tells rbenv to use the system Ruby
  250. (detected by searching your `$PATH`).
  251. When run without a version number, `rbenv global` reports the
  252. currently configured global version.
  253. ### rbenv shell
  254. Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
  255. environment variable in your shell. This version overrides
  256. application-specific versions and the global version.
  257. $ rbenv shell jruby-1.7.1
  258. When run without a version number, `rbenv shell` reports the current
  259. value of `RBENV_VERSION`. You can also unset the shell version:
  260. $ rbenv shell --unset
  261. Note that you'll need rbenv's shell integration enabled (step 3 of
  262. the installation instructions) in order to use this command. If you
  263. prefer not to use shell integration, you may simply set the
  264. `RBENV_VERSION` variable yourself:
  265. $ export RBENV_VERSION=jruby-1.7.1
  266. ### rbenv versions
  267. Lists all Ruby versions known to rbenv, and shows an asterisk next to
  268. the currently active version.
  269. $ rbenv versions
  270. 1.8.7-p352
  271. 1.9.2-p290
  272. * 1.9.3-p327 (set by /Users/sam/.rbenv/version)
  273. jruby-1.7.1
  274. rbx-1.2.4
  275. ree-1.8.7-2011.03
  276. ### rbenv version
  277. Displays the currently active Ruby version, along with information on
  278. how it was set.
  279. $ rbenv version
  280. 1.8.7-p352 (set by /Volumes/37signals/basecamp/.ruby-version)
  281. ### rbenv rehash
  282. Installs shims for all Ruby executables known to rbenv (i.e.,
  283. `~/.rbenv/versions/*/bin/*`). Run this command after you install a new
  284. version of Ruby, or install a gem that provides commands.
  285. $ rbenv rehash
  286. ### rbenv which
  287. Displays the full path to the executable that rbenv will invoke when
  288. you run the given command.
  289. $ rbenv which irb
  290. /Users/sam/.rbenv/versions/1.9.3-p327/bin/irb
  291. ### rbenv whence
  292. Lists all Ruby versions with the given command installed.
  293. $ rbenv whence rackup
  294. 1.9.3-p327
  295. jruby-1.7.1
  296. ree-1.8.7-2011.03
  297. ## Development
  298. The rbenv source code is [hosted on
  299. GitHub](https://github.com/sstephenson/rbenv). It's clean, modular,
  300. and easy to understand, even if you're not a shell hacker.
  301. Tests are executed using [Bats](https://github.com/sstephenson/bats):
  302. $ bats test
  303. $ bats test/<file>.bats
  304. Please feel free to submit pull requests and file bugs on the [issue
  305. tracker](https://github.com/sstephenson/rbenv/issues).
  306. ### Version History
  307. **0.4.0** (January 4, 2013)
  308. * rbenv now prefers `.ruby-version` files to `.rbenv-version` files
  309. for specifying local application-specific versions. The
  310. `.ruby-version` file has the same format as `.rbenv-version` but is
  311. [compatible with other Ruby version
  312. managers](https://gist.github.com/1912050).
  313. * Deprecated `ruby-local-exec` and moved its functionality into the
  314. standard `ruby` shim. See the [ruby-local-exec wiki
  315. page](https://github.com/sstephenson/rbenv/wiki/ruby-local-exec) for
  316. upgrade instructions.
  317. * Modified shims to include the full path to rbenv so that they can be
  318. invoked without having rbenv's bin directory in the `$PATH`.
  319. * Sped up `rbenv init` by avoiding rbenv reinitialization and by
  320. using a simpler indexing approach. (Users of
  321. [chef-rbenv](https://github.com/fnichol/chef-rbenv) should upgrade
  322. to the latest version to fix a [compatibility
  323. issue](https://github.com/fnichol/chef-rbenv/pull/26).)
  324. * Reworked `rbenv help` so that usage and documentation is stored as a
  325. comment in each subcommand, enabling plugin commands to hook into
  326. the help system.
  327. * Added support for full completion of the command line, not just the
  328. first argument.
  329. * Updated installation instructions for Zsh and Ubuntu users.
  330. * Fixed `rbenv which` and `rbenv prefix` with system Ruby versions.
  331. * Changed `rbenv exec` to avoid prepending the system Ruby location to
  332. `$PATH` to fix issues running system Ruby commands that invoke other
  333. commands.
  334. * Changed `rbenv rehash` to ensure it exits with a 0 status code under
  335. normal operation, and to ensure outdated shims are removed first
  336. when rehashing.
  337. * Modified `rbenv rehash` to run `hash -r` afterwards, when shell
  338. integration is enabled, to ensure the shell's command cache is
  339. cleared.
  340. * Removed use of the `+=` operator to support older versions of Bash.
  341. * Adjusted non-bare `rbenv versions` output to include `system`, if
  342. present.
  343. * Improved documentation for installing and uninstalling Ruby
  344. versions.
  345. * Fixed `rbenv versions` not to display a warning if the currently
  346. specified version doesn't exist.
  347. * Fixed an instance of local variable leakage in the `rbenv` shell
  348. function wrapper.
  349. * Changed `rbenv shell` to ensure it exits with a non-zero status on
  350. failure.
  351. * Added `rbenv --version` for printing the current version of rbenv.
  352. * Added `/usr/lib/rbenv/hooks` to the plugin hook search path.
  353. * Fixed `rbenv which` to account for path entries with spaces.
  354. * Changed `rbenv init` to accept option arguments in any order.
  355. **0.3.0** (December 25, 2011)
  356. * Added an `rbenv root` command which prints the value of
  357. `$RBENV_ROOT`, or the default root directory if it's unset.
  358. * Clarified Zsh installation instructions in the Readme.
  359. * Removed some redundant code in `rbenv rehash`.
  360. * Fixed an issue with calling `readlink` for paths with spaces.
  361. * Changed Zsh initialization code to install completion hooks only for
  362. interactive shells.
  363. * Added preliminary support for ksh.
  364. * `rbenv rehash` creates or removes shims only when necessary instead
  365. of removing and re-creating all shims on each invocation.
  366. * Fixed that `RBENV_DIR`, when specified, would be incorrectly
  367. expanded to its parent directory.
  368. * Removed the deprecated `set-default` and `set-local` commands.
  369. * Added a `--no-rehash` option to `rbenv init` for skipping the
  370. automatic rehash when opening a new shell.
  371. **0.2.1** (October 1, 2011)
  372. * Changed the `rbenv` command to ensure that `RBENV_DIR` is always an
  373. absolute path. This fixes an issue where Ruby scripts using the
  374. `ruby-local-exec` wrapper would go into an infinite loop when
  375. invoked with a relative path from the command line.
  376. **0.2.0** (September 28, 2011)
  377. * Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local`
  378. to `rbenv local`. The `set-` commands are deprecated and will be
  379. removed in the next major release.
  380. * rbenv now uses `greadlink` on Solaris.
  381. * Added a `ruby-local-exec` command which can be used in shebangs in
  382. place of `#!/usr/bin/env ruby` to properly set the project-specific
  383. Ruby version regardless of current working directory.
  384. * Fixed an issue with `rbenv rehash` when no binaries are present.
  385. * Added support for `rbenv-sh-*` commands, which run inside the
  386. current shell instead of in a child process.
  387. * Added an `rbenv shell` command for conveniently setting the
  388. `$RBENV_VERSION` environment variable.
  389. * Added support for storing rbenv versions and shims in directories
  390. other than `~/.rbenv` with the `$RBENV_ROOT` environment variable.
  391. * Added support for debugging rbenv via `set -x` when the
  392. `$RBENV_DEBUG` environment variable is set.
  393. * Refactored the autocompletion system so that completions are now
  394. built-in to each command and shared between bash and Zsh.
  395. * Added support for plugin bundles in `~/.rbenv/plugins` as documented
  396. in [issue #102](https://github.com/sstephenson/rbenv/pull/102).
  397. * Added `/usr/local/etc/rbenv.d` to the list of directories searched
  398. for rbenv hooks.
  399. * Added support for an `$RBENV_DIR` environment variable which
  400. defaults to the current working directory for specifying where rbenv
  401. searches for local version files.
  402. **0.1.2** (August 16, 2011)
  403. * Fixed rbenv to be more resilient against nonexistent entries in
  404. `$PATH`.
  405. * Made the `rbenv rehash` command operate atomically.
  406. * Modified the `rbenv init` script to automatically run `rbenv
  407. rehash` so that shims are recreated whenever a new shell is opened.
  408. * Added initial support for Zsh autocompletion.
  409. * Removed the dependency on egrep for reading version files.
  410. **0.1.1** (August 14, 2011)
  411. * Fixed a syntax error in the `rbenv help` command.
  412. * Removed `-e` from the shebang in favor of `set -e` at the top of
  413. each file for compatibility with operating systems that do not
  414. support more than one argument in the shebang.
  415. **0.1.0** (August 11, 2011)
  416. * Initial public release.
  417. ### License
  418. (The MIT license)
  419. Copyright (c) 2013 Sam Stephenson
  420. Permission is hereby granted, free of charge, to any person obtaining
  421. a copy of this software and associated documentation files (the
  422. "Software"), to deal in the Software without restriction, including
  423. without limitation the rights to use, copy, modify, merge, publish,
  424. distribute, sublicense, and/or sell copies of the Software, and to
  425. permit persons to whom the Software is furnished to do so, subject to
  426. the following conditions:
  427. The above copyright notice and this permission notice shall be
  428. included in all copies or substantial portions of the Software.
  429. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  430. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  431. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  432. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  433. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  434. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  435. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  436. [ruby-build]: https://github.com/sstephenson/ruby-build#readme