Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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