OSDN Git Service

Regular updates
[twpd/master.git] / rbenv.md
1 ---
2 title: rbenv
3 category: Ruby
4 layout: 2017/sheet
5 updated: 2018-02-20
6 weight: -1
7 description: |
8   A one-page guide to rbenv Ruby version manager, with usage examples and more.
9 intro: |
10   [rbenv](https://github.com/rbenv/rbenv) lets you manage installations of multiple Ruby versions.
11 ---
12
13 ### Installation
14
15 #### Install rbenv and ruby-build
16
17 ```bash
18 git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
19 git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
20 ```
21
22 #### Add to ~/.bash_profile
23
24 ```bash
25 echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
26 echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
27 ```
28
29 #### Verify installation
30
31 ```bash
32 type rbenv   # → "rbenv is a function"
33 ```
34
35 These are generic instructions; there may be rbenv packages available for your OS.
36
37 See: [Installation](https://github.com/rbenv/rbenv#installation)
38
39 ### Managing versions
40
41 | Command                 | Description                 |
42 | ---                     | ---                         |
43 | `rbenv install -l`      | List all available versions |
44 | ---                     | ---                         |
45 | `rbenv install 2.2.1`   | Install Ruby _2.2.1_        |
46 | `rbenv uninstall 2.2.1` | Uninstall Ruby _2.2.1_      |
47 | ---                     | ---                         |
48 | `rbenv versions`        | See installed versions      |
49 | `rbenv version`         | See current version         |
50 | ---                     | ---                         |
51 | `rbenv which <NAME>`    | Display path to executable  |
52 | `rbenv rehash`          | Re-write binstubs           |
53
54 ## Using versions
55 {: .-three-column}
56
57 ### Locally
58
59 | Command               | Description                 |
60 | ---                   | ---                         |
61 | `rbenv local 2.2.2`   | Use Ruby _2.2.2_ in project |
62 | `rbenv local --unset` | Undo above                  |
63
64 Application-specific version numbers are stored in `.ruby-version`.
65
66 ### Globally
67
68 | Command                | Description               |
69 | ---                    | ---                       |
70 | `rbenv global 2.2.2`   | Use Ruby _2.2.2_ globally |
71 | `rbenv global --unset` | Undo above                |
72
73 Global version numbers are stored in `~/.rbenv/version`.
74
75 ### Shell
76
77 | Command               | Description               |
78 | ---                   | ---                       |
79 | `rbenv shell 2.2.2`   | Use Ruby _2.2.2_ in shell |
80 | `rbenv shell --unset` | Undo above                |
81
82 Shell-local version numbers are stored as environment variables.
83
84 ## References
85
86 - [rbenv project page](https://github.com/rbenv/rbenv) _(github.com)_
87 - [rbenv ubuntu server cheatsheet](https://gist.github.com/rahul286/7160839f4425a3b7e718) _(gist.github.com)_