cheatsheets/rbenv.md

87 lines
2.6 KiB
Markdown
Raw Permalink Normal View History

2017-10-11 01:01:01 +00:00
---
title: rbenv
category: Ruby
2020-07-04 13:33:09 +00:00
updated: 2018-02-20
2017-10-11 01:03:14 +00:00
weight: -1
2017-10-11 01:01:01 +00:00
description: |
A one-page guide to rbenv Ruby version manager, with usage examples and more.
intro: |
[rbenv](https://github.com/rbenv/rbenv) lets you manage installations of multiple Ruby versions.
---
### Installation
#### Install rbenv and ruby-build
```bash
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
```
2017-10-11 01:02:23 +00:00
#### Add to ~/.bash_profile
2017-10-11 01:01:01 +00:00
```bash
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
```
#### Verify installation
```bash
type rbenv # → "rbenv is a function"
```
These are generic instructions; there may be rbenv packages available for your OS.
See: [Installation](https://github.com/rbenv/rbenv#installation)
### Managing versions
| Command | Description |
| --- | --- |
| `rbenv install -l` | List all available versions |
| --- | --- |
| `rbenv install 2.2.1` | Install Ruby _2.2.1_ |
| `rbenv uninstall 2.2.1` | Uninstall Ruby _2.2.1_ |
| --- | --- |
| `rbenv versions` | See installed versions |
| `rbenv version` | See current version |
| --- | --- |
| `rbenv which <NAME>` | Display path to executable |
| `rbenv rehash` | Re-write binstubs |
## Using versions
{: .-three-column}
### Locally
2018-02-20 15:53:18 +00:00
| Command | Description |
| --- | --- |
2017-10-11 01:01:01 +00:00
| `rbenv local 2.2.2` | Use Ruby _2.2.2_ in project |
| `rbenv local --unset` | Undo above |
Application-specific version numbers are stored in `.ruby-version`.
### Globally
2018-02-20 15:53:18 +00:00
| Command | Description |
| --- | --- |
2017-10-11 01:01:01 +00:00
| `rbenv global 2.2.2` | Use Ruby _2.2.2_ globally |
2018-02-20 15:53:18 +00:00
| `rbenv global --unset` | Undo above |
2017-10-11 01:01:01 +00:00
Global version numbers are stored in `~/.rbenv/version`.
### Shell
2018-02-20 15:53:18 +00:00
| Command | Description |
| --- | --- |
2017-10-11 01:01:01 +00:00
| `rbenv shell 2.2.2` | Use Ruby _2.2.2_ in shell |
| `rbenv shell --unset` | Undo above |
Shell-local version numbers are stored as environment variables.
## References
- [rbenv project page](https://github.com/rbenv/rbenv) _(github.com)_
- [rbenv ubuntu server cheatsheet](https://gist.github.com/rahul286/7160839f4425a3b7e718) _(gist.github.com)_