Set Up Rbenv Revisited
I have been working on setting up a new operating system distribution. I took some time to test out a different package manager, but ended up going back to my familiar toolset. This article discusses the package manager for managing Ruby versions.
Package Managers
So what is a package manager?
A package manager or package-management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer's operating system consistently.
They give you the ability to manage multiple versions of the same packages (i.e., Node.js, Ruby, etc.).
When it comes to Ruby, there are three major package managers to consider.
RVM - When I first started learning Ruby almost two years ago and set up my MacBook Pro, I used RVM. It worked fine, and I had no real issues. However, it seemed heavy in terms of computer resources.
ASDF - this is a different package manager because it is language-agnostic. You can install a plugin for the respective language (e.g., Ruby, Node.js).
RBENV - this is my preference, and the focus of this article. A major pull rbenv for me is that it's lighter, and by that I mean that it doesn't have to throw as many hooks into your computer system as does rvm, although there is some load to the terminal. This is why I N to manage Node versus NVM there is ZERO terminal load. This may be the source of another article.
Enter the Clones
So, Homebrew offers a rbenv package install, and Ubuntu does as well. I have used both, but I prefer to have more control, so I clone the repositories. To set up RBENV, there is a default way:
- Clone rbenv to
.rbenv - Clone rbenv-build to
.rbenv/plugins - Set up
.rbenv/binin your$PATH - Set up
.rbenv/bin/rbenv initin your shell - Restart shell
- Run the rbenv-doctor script to verify installation
Thankfully, there is an easier install script. This script installs or updates rbenv on your system. If Homebrew is detected, installation will proceed using brew install/upgrade. Otherwise, rbenv is installed under ~/.rbenv. Additionally, ruby-build is also installed if rbenv install is not already available. After the installation, a separate rbenv-doctor A script is run to verify the installation's success and detect common issues.
# with curl
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash
# alternatively, with wget
wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer -O- | bash
Default Gems
There is one rbenv plugin that I prefer to set up, and that is rbenv-default-gems. This plugin will manage installing a select set of gems whenever you update your version of ruby. Install the plugin:
git clone https://github.com/rbenv/rbenv-default-gems.git $(rbenv root)/plugins/rbenv-default-gems
Create a simple text file: touch ~/.rbenv/default-gems. In this file, create your link of preferred gems to install/update:
bundler
rails
Now install your Ruby version: rbenv install 3.0.0
Updating
When new versions of Ruby are released, it is important to update rbenv. There are two ways to do this. Since you have literally cloned the repository, you can git pull, but there are two directories to do that in:
cd ~/.rbenv
git pull
And for ruby-build
cd ~/.rbenv/plugins/ruby-build
git pull
Check on Ruby versions to install:
# list latest stable versions:
$ rbenv install -l
# list all local versions:
$ rbenv install -L
# install a Ruby version:
$ rbenv install 2.7.2