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

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