1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-16 23:33:45 -05:00

rbenv init: modify shell config files instead of printing instructions (#1568)

When running `rbenv init`, typically during rbenv setup, users expected
their shell environment to be modified permanently. Instead, what the
command would do is print the instructions to the user and expect them
to edit their shell initialization files accordingly. This proved to
be unintuitive.

Now, running `rbenv init <shells>...` will modify the shell initialization
files of the following shells:

- bash: `~/.bash_profile` or `~/.bashrc` if the latter exists but the former does not
- zsh: `~/.zprofile` or `~/.zshrc` if the latter exists and mentions "rbenv"
- fish: `~/.config/fish/config.fish`

If no shells were specified on the command line, rbenv will try to detect
the current shell.

It should be safe to run `rbenv init` multiple times, as the command will
avoid modifying any shell startup file that already mentions "rbenv init".
This commit is contained in:
Mislav Marohnić
2024-05-03 16:59:39 +02:00
committed by GitHub
parent a3b98a4223
commit c3ba994ec2
3 changed files with 151 additions and 81 deletions

View File

@@ -51,10 +51,9 @@ On systems with Homebrew package manager, the “Using Package Managers” metho
rbenv and you can install it from the AUR using the instructions from this
[wiki page](https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_and_upgrading_packages).
2. Learn how to load rbenv in your shell.
2. Set up your shell to load rbenv.
```sh
# run this and follow the printed instructions:
rbenv init
```
@@ -75,29 +74,11 @@ This will get you going with the latest version of rbenv without needing a syste
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
```
2. Configure your shell to load rbenv:
2. Set up your shell to load rbenv.
* For **bash**:
_Ubuntu Desktop_ users should configure `~/.bashrc`:
```bash
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
```
On _other platforms_, bash is usually configured via `~/.bash_profile`:
```bash
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bash_profile
```
* For **Zsh**:
```zsh
echo 'eval "$(~/.rbenv/bin/rbenv init - zsh)"' >> ~/.zshrc
```
* For **Fish shell**:
```fish
echo 'status --is-interactive; and ~/.rbenv/bin/rbenv init - fish | source' >> ~/.config/fish/config.fish
```
```sh
~/.rbenv/bin/rbenv init
```
If you are curious, see here to [understand what `init` does](#how-rbenv-hooks-into-your-shell).
@@ -298,7 +279,7 @@ name | default | description
### How rbenv hooks into your shell
`rbenv init` is a helper command to bootstrap rbenv into a shell. This helper is part of the recommended installation instructions, but optional, as an advanced user can set up the following tasks manually. Here is what the command does when its output is `eval`'d:
`rbenv init` is a helper command to bootstrap rbenv into a shell. This helper is part of the recommended installation instructions, but optional, as an advanced user can set up the following tasks manually. Here is what the command does when its output is `eval`'d by a shell during its startup:
0. Adds `rbenv` executable to PATH if necessary.