You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

396 lines
14 KiB

пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
  1. # Simple Ruby Version Management: rbenv
  2. rbenv lets you easily switch between multiple versions of Ruby. It's
  3. simple, unobtrusive, and follows the UNIX tradition of single-purpose
  4. tools that do one thing well.
  5. <img src="http://i.sstephenson.us/rbenv.png" width="894" height="464">
  6. ### rbenv _does…_
  7. * Let you **change the global Ruby version** on a per-user basis.
  8. * Provide support for **per-project Ruby versions**.
  9. * Allow you to **override the Ruby version** with an environment
  10. variable.
  11. ### In contrast with rvm, rbenv _does not…_
  12. * **Need to be loaded into your shell.** Instead, rbenv's shim
  13. approach works by adding a directory to your `$PATH`.
  14. * **Override shell commands like `cd`.** That's dangerous and
  15. error-prone.
  16. * **Have a configuration file.** There's nothing to configure except
  17. which version of Ruby you want to use.
  18. * **Install Ruby.** You can build and install Ruby yourself, or use
  19. [ruby-build](https://github.com/sstephenson/ruby-build) to
  20. automate the process.
  21. * **Manage gemsets.** [Bundler](http://gembundler.com/) is a better
  22. way to manage application dependencies. If you have projects that
  23. are not yet using Bundler you can install the
  24. [rbenv-gemset](https://github.com/jamis/rbenv-gemset) plugin.
  25. * **Require changes to Ruby libraries for compatibility.** The
  26. simplicity of rbenv means as long as it's in your `$PATH`,
  27. [nothing](https://rvm.beginrescueend.com/integration/bundler/)
  28. [else](https://rvm.beginrescueend.com/integration/capistrano/)
  29. needs to know about it.
  30. * **Prompt you with warnings when you switch to a project.** Instead
  31. of executing arbitrary code, rbenv reads just the version name
  32. from each project. There's nothing to "trust."
  33. ## Table of Contents
  34. * [1 How It Works](#section_1)
  35. * [2 Installation](#section_2)
  36. * [2.1 Basic GitHub Checkout](#section_2.1)
  37. * [2.1.1 Upgrading](#section_2.1.1)
  38. * [2.2 Homebrew on Mac OS X](#section_2.2)
  39. * [2.3 Neckbeard Configuration](#section_2.3)
  40. * [3 Usage](#section_3)
  41. * [3.1 rbenv global](#section_3.1)
  42. * [3.2 rbenv local](#section_3.2)
  43. * [3.3 rbenv shell](#section_3.3)
  44. * [3.4 rbenv versions](#section_3.4)
  45. * [3.5 rbenv version](#section_3.5)
  46. * [3.6 rbenv rehash](#section_3.6)
  47. * [3.7 rbenv which](#section_3.7)
  48. * [3.8 rbenv whence](#section_3.8)
  49. * [4 Development](#section_4)
  50. * [4.1 Version History](#section_4.1)
  51. * [4.2 License](#section_4.2)
  52. ## <a name="section_1"></a> 1 How It Works
  53. rbenv operates on the per-user directory `~/.rbenv`. Version names in
  54. rbenv correspond to subdirectories of `~/.rbenv/versions`. For
  55. example, you might have `~/.rbenv/versions/1.8.7-p354` and
  56. `~/.rbenv/versions/1.9.3-rc1`.
  57. Each version is a working tree with its own binaries, like
  58. `~/.rbenv/versions/1.8.7-p354/bin/ruby` and
  59. `~/.rbenv/versions/1.9.3-rc1/bin/irb`. rbenv makes _shim binaries_
  60. for every such binary across all installed versions of Ruby.
  61. These shims are simple wrapper scripts that live in `~/.rbenv/shims`
  62. and detect which Ruby version you want to use. They insert the
  63. directory for the selected version at the beginning of your `$PATH`
  64. and then execute the corresponding binary.
  65. Because of the simplicity of the shim approach, all you need to use
  66. rbenv is `~/.rbenv/shims` in your `$PATH`.
  67. ## <a name="section_2"></a> 2 Installation
  68. **Compatibility note**: rbenv is _incompatible_ with rvm. Things will
  69. appear to work until you try to install a gem. The problem is that
  70. rvm actually overrides the `gem` command with a shell function!
  71. Please remove any references to rvm before using rbenv.
  72. ### <a name="section_2.1"></a> 2.1 Basic GitHub Checkout
  73. This will get you going with the latest version of rbenv and make it
  74. easy to fork and contribute any changes back upstream.
  75. 1. Check out rbenv into `~/.rbenv`.
  76. $ cd
  77. $ git clone git://github.com/sstephenson/rbenv.git .rbenv
  78. 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv`
  79. command-line utility.
  80. $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
  81. **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
  82. 3. Add rbenv init to your shell to enable shims and autocompletion.
  83. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
  84. **Zsh note**: Modifiy your `~/.zshenv` file instead of `~/.bash_profile`.
  85. 4. Restart your shell so the path changes take effect. You can now
  86. begin using rbenv.
  87. $ exec $SHELL
  88. 5. Install Ruby versions into `~/.rbenv/versions`. For example, to
  89. install Ruby 1.9.2-p290, download and unpack the source, then run:
  90. $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290
  91. $ make
  92. $ make install
  93. The [ruby-build](https://github.com/sstephenson/ruby-build) project
  94. provides an `rbenv install` command that simplifies the process of
  95. installing new Ruby versions to:
  96. $ rbenv install 1.9.2-p290
  97. 6. Rebuild the shim binaries. You should do this any time you install
  98. a new Ruby binary (for example, when installing a new Ruby version,
  99. or when installing a gem that provides a binary).
  100. $ rbenv rehash
  101. #### <a name="section_2.1.1"></a> 2.1.1 Upgrading
  102. If you've installed rbenv using the instructions above, you can
  103. upgrade your installation at any time using git.
  104. To upgrade to the latest development version of rbenv, use `git pull`:
  105. $ cd ~/.rbenv
  106. $ git pull
  107. To upgrade to a specific release of rbenv, check out the corresponding
  108. tag:
  109. $ cd ~/.rbenv
  110. $ git fetch
  111. $ git tag
  112. v0.1.0
  113. v0.1.1
  114. v0.1.2
  115. v0.2.0
  116. $ git checkout v0.2.0
  117. ### <a name="section_2.2"></a> 2.2 Homebrew on Mac OS X
  118. You can also install rbenv using the
  119. [Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS
  120. X.
  121. $ brew update
  122. $ brew install rbenv
  123. $ brew install ruby-build
  124. The same commands can be used for upgrading.
  125. Afterwards you'll still need to add `eval "$(rbenv init -)"` to your
  126. profile as stated in the caveats. You'll only ever have to do this
  127. once.
  128. ### <a name="section_2.3"></a> 2.3 Neckbeard Configuration
  129. Skip this section unless you must know what every line in your shell
  130. profile is doing.
  131. `rbenv init` is the only command that crosses the line of loading
  132. extra commands into your shell. Coming from rvm, some of you might be
  133. opposed to this idea. Here's what `rbenv init` actually does:
  134. 1. Sets up your shims path. This is the only requirement for rbenv to
  135. function properly. You can do this by hand by prepending
  136. `~/.rbenv/shims` to your `$PATH`.
  137. 2. Installs autocompletion. This is entirely optional but pretty
  138. useful. Sourcing `~/.rbenv/completions/rbenv.bash` will set that
  139. up. There is also a `~/.rbenv/completions/rbenv.zsh` for Zsh
  140. users.
  141. 3. Rehashes shims. From time to time you'll need to rebuild your
  142. shim files. Doing this on init makes sure everything is up to
  143. date. You can always run `rbenv rehash` manually.
  144. 4. Installs the sh dispatcher. This bit is also optional, but allows
  145. rbenv and plugins to change variables in your current shell, making
  146. commands like `rbenv shell` possible. The sh dispatcher doesn't do
  147. anything crazy like override `cd` or hack your shell prompt, but if
  148. for some reason you need `rbenv` to be a real script rather than a
  149. shell function, you can safely skip it.
  150. Run `rbenv init -` for yourself to see exactly what happens under the
  151. hood.
  152. ## <a name="section_3"></a> 3 Usage
  153. Like `git`, the `rbenv` command delegates to subcommands based on its
  154. first argument. The most common subcommands are:
  155. ### <a name="section_3.1"></a> 3.1 rbenv global
  156. Sets the global version of Ruby to be used in all shells by writing
  157. the version name to the `~/.rbenv/version` file. This version can be
  158. overridden by a per-project `.rbenv-version` file, or by setting the
  159. `RBENV_VERSION` environment variable.
  160. $ rbenv global 1.9.2-p290
  161. The special version name `system` tells rbenv to use the system Ruby
  162. (detected by searching your `$PATH`).
  163. When run without a version number, `rbenv global` reports the
  164. currently configured global version.
  165. ### <a name="section_3.2"></a> 3.2 rbenv local
  166. Sets a local per-project Ruby version by writing the version name to
  167. an `.rbenv-version` file in the current directory. This version
  168. overrides the global, and can be overridden itself by setting the
  169. `RBENV_VERSION` environment variable or with the `rbenv shell`
  170. command.
  171. $ rbenv local rbx-1.2.4
  172. When run without a version number, `rbenv local` reports the currently
  173. configured local version. You can also unset the local version:
  174. $ rbenv local --unset
  175. ### <a name="section_3.3"></a> 3.3 rbenv shell
  176. Sets a shell-specific Ruby version by setting the `RBENV_VERSION`
  177. environment variable in your shell. This version overrides both
  178. project-specific versions and the global version.
  179. $ rbenv shell jruby-1.6.4
  180. When run without a version number, `rbenv shell` reports the current
  181. value of `RBENV_VERSION`. You can also unset the shell version:
  182. $ rbenv shell --unset
  183. Note that you'll need rbenv's shell integration enabled (step 3 of
  184. the installation instructions) in order to use this command. If you
  185. prefer not to use shell integration, you may simply set the
  186. `RBENV_VERSION` variable yourself:
  187. $ export RBENV_VERSION=jruby-1.6.4
  188. ### <a name="section_3.4"></a> 3.4 rbenv versions
  189. Lists all Ruby versions known to rbenv, and shows an asterisk next to
  190. the currently active version.
  191. $ rbenv versions
  192. 1.8.7-p352
  193. 1.9.2-p290
  194. * 1.9.3-rc1 (set by /Users/sam/.rbenv/global)
  195. jruby-1.6.4
  196. rbx-1.2.4
  197. ree-1.8.7-2011.03
  198. ### <a name="section_3.5"></a> 3.5 rbenv version
  199. Displays the currently active Ruby version, along with information on
  200. how it was set.
  201. $ rbenv version
  202. 1.8.7-p352 (set by /Volumes/37signals/basecamp/.rbenv-version)
  203. ### <a name="section_3.6"></a> 3.6 rbenv rehash
  204. Installs shims for all Ruby binaries known to rbenv (i.e.,
  205. `~/.rbenv/versions/*/bin/*`). Run this command after you install a new
  206. version of Ruby, or install a gem that provides binaries.
  207. $ rbenv rehash
  208. ### <a name="section_3.7"></a> 3.7 rbenv which
  209. Displays the full path to the binary that rbenv will execute when you
  210. run the given command.
  211. $ rbenv which irb
  212. /Users/sam/.rbenv/versions/1.9.2-p290/bin/irb
  213. ### <a name="section_3.8"></a> 3.8 rbenv whence
  214. Lists all Ruby versions with the given command installed.
  215. $ rbenv whence rackup
  216. 1.9.3-rc1
  217. jruby-1.6.4
  218. ree-1.8.7-2011.03
  219. ## <a name="section_4"></a> 4 Development
  220. The rbenv source code is [hosted on
  221. GitHub](https://github.com/sstephenson/rbenv). It's clean, modular,
  222. and easy to understand, even if you're not a shell hacker.
  223. Please feel free to submit pull requests and file bugs on the [issue
  224. tracker](https://github.com/sstephenson/rbenv/issues).
  225. ### <a name="section_4.1"></a> 4.1 Version History
  226. **0.2.1** (October 1, 2011)
  227. * Changed the `rbenv` command to ensure that `RBENV_DIR` is always an
  228. absolute path. This fixes an issue where Ruby scripts using the
  229. `ruby-local-exec` wrapper would go into an infinite loop when
  230. invoked with a relative path from the command line.
  231. **0.2.0** (September 28, 2011)
  232. * Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local`
  233. to `rbenv local`. The `set-` commands are deprecated and will be
  234. removed in the next major release.
  235. * rbenv now uses `greadlink` on Solaris.
  236. * Added a `ruby-local-exec` command which can be used in shebangs in
  237. place of `#!/usr/bin/env ruby` to properly set the project-specific
  238. Ruby version regardless of current working directory.
  239. * Fixed an issue with `rbenv rehash` when no binaries are present.
  240. * Added support for `rbenv-sh-*` commands, which run inside the
  241. current shell instead of in a child process.
  242. * Added an `rbenv shell` command for conveniently setting the
  243. `$RBENV_VERSION` environment variable.
  244. * Added support for storing rbenv versions and shims in directories
  245. other than `~/.rbenv` with the `$RBENV_ROOT` environment variable.
  246. * Added support for debugging rbenv via `set -x` when the
  247. `$RBENV_DEBUG` environment variable is set.
  248. * Refactored the autocompletion system so that completions are now
  249. built-in to each command and shared between bash and Zsh.
  250. * Added support for plugin bundles in `~/.rbenv/plugins` as documented
  251. in [issue #102](https://github.com/sstephenson/rbenv/pull/102).
  252. * Added `/usr/local/etc/rbenv.d` to the list of directories searched
  253. for rbenv hooks.
  254. * Added support for an `$RBENV_DIR` environment variable which
  255. defaults to the current working directory for specifying where rbenv
  256. searches for local version files.
  257. **0.1.2** (August 16, 2011)
  258. * Fixed rbenv to be more resilient against nonexistent entries in
  259. `$PATH`.
  260. * Made the `rbenv rehash` command operate atomically.
  261. * Modified the `rbenv init` script to automatically run `rbenv
  262. rehash` so that shims are recreated whenever a new shell is opened.
  263. * Added initial support for Zsh autocompletion.
  264. * Removed the dependency on egrep for reading version files.
  265. **0.1.1** (August 14, 2011)
  266. * Fixed a syntax error in the `rbenv help` command.
  267. * Removed `-e` from the shebang in favor of `set -e` at the top of
  268. each file for compatibility with operating systems that do not
  269. support more than one argument in the shebang.
  270. **0.1.0** (August 11, 2011)
  271. * Initial public release.
  272. ### <a name="section_4.2"></a> 4.2 License
  273. (The MIT license)
  274. Copyright (c) 2011 Sam Stephenson
  275. Permission is hereby granted, free of charge, to any person obtaining
  276. a copy of this software and associated documentation files (the
  277. "Software"), to deal in the Software without restriction, including
  278. without limitation the rights to use, copy, modify, merge, publish,
  279. distribute, sublicense, and/or sell copies of the Software, and to
  280. permit persons to whom the Software is furnished to do so, subject to
  281. the following conditions:
  282. The above copyright notice and this permission notice shall be
  283. included in all copies or substantial portions of the Software.
  284. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  285. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  286. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  287. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  288. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  289. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  290. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.