How to use rbenv
Install rbenv and its plugins
Rbenv has the basic functionality but it requires plugins for all desired features:
- ruby-build: Installing Ruby versions.
- rbenv-gemset: Managing gemsets.
- …
To have more control on it, install it using git:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'eval "$(~/.rbenv/bin/rbenv init - zsh)"' >> ~/.zshrc
Restart shell.
Install plugins:
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
$ git clone https://github.com/jf/rbenv-gemset.git $HOME/.rbenv/plugins/rbenv-gemset
Install Ruby version
List versions:
rbenv install --list
Install:
rbenv install 3.3.0
Set default Ruby version globally:
rbenv global 3.3.0
Set Ruby version for directoy:
rbenv local 3.3.0
Set Ruby version for the shell:
rbenv shell 3.3.0
Use gemsets
Gemset in custom directory
Create a gemset by specifying the directory where gems should be installed so that you can cleanup or test easily:
cd project-directoy
echo '.gems' > .rbenv-gemsets
When you run bundle install
or gem install
, the gems will be installed in project-directory/.gems
.
To see where your gems are being installed, run:
gem env home
Gemsets in default directory
Init a gemset:
rbenv gemset init [gemset-name]
Create gemset under specific Ruby version:
cd project-directory
rbenv gemset create [ruby-version] [gemset-name]
List existing gemsets:
rbenv gemset list
Delete gemset:
rbenv gemset delete [ruby-version] [gemset-name]