Setup

Switching to asdf

Switching from rbenv to asdf for managing my Ruby installations, and start using asdf for managing Node.js and Python runtimes.

Wolfgang Rittner

updated June 30, 2024 · 3 min read

I'm setting up my primary work laptop from scratch about once a year, and while doing so I'm reevaluating what's working for me, and what things I want to try to change and - 🤞 - improve.

I want to improve how I handle nodejs installations. I'm working with Ruby and Rails as much as I can, still almost every project needs nodejs and friends available for frontend concerns.
Never thought much about it and I've no idea what's going on most if the time, it's all chaos and works by accident at best.

Old is boring

For managing different ruby versions I've been using rbenv for ages, which works as advertised and never gave me any trouble.
Now that can't be! This needs to change. Wait, what?

I'm also heavily relying on gemsets. I dread, like really, utterly dread, having to use bundle exec all the time. My solution was to have a gemset for each project and additionally putting ./bin in front of my PATH.

What's your strategy as a Rubyist? Let me know!

Meet asdf

Some time ago I stumbled upon a tool called asdf. It is a CLI tool for managing multiple runtime versions. It supports the fish shell, which I'm using, and there are a ton of plugins including ones for Ruby and Node.js.
It sounded like it would be a good fit for managing my rubies as well as my nodejs... nodejses... nodejies, so I decided to give it a try. I figured I could always return to old, boring and chaos should things not work out with asdf.

The major change to my previous setup is that asdf, or rather its ruby plugin, does not support gemsets at all. That sounded like quite a bummer, but I'm determined to give it a try. It would make my setup more standard.
I will not start typing bundle exec all the time. This new setup still needs to bend to my will. We'll see how that goes.

Update: I'm using bundle binstubs as an alternative to bundle exec.

Setup

Most of asdf's functionality is provided by plugins. You install the main app and then pick and choose what plugins you want to use based on your needs.

Installing asdf itself is straight-forward using brew, and there is awesome documentation for all kinds of platforms and package managers.

There's probably just one thing that you want to configure and that's the support for what they call "legacy version files". By activating support for legacy file versions, asdf will pick up any .ruby-version files you might already use in existing projects.
Out of the box asdf only looks for a .tool-versions file.

I'm not yet sure if I'm going to adopt that, or if I'm going to stick to "legacy" version files.

I installed the main app following steps from asdf's docs, then added the plugins for ruby and nodejs and configured support for legacy version files.

bash
# get the main app
brew install asdf

# set up fish shell integration
echo -e "\nsource "(brew --prefix asdf)"/asdf.fish" >> ~/.config/fish/config.fish

# now close and open terminal to reload the fish config

# next install asdf plugins
asdf plugin add ruby

asdf plugin add nodejs

Usage

You should now be able to install ruby and node.js using asdf, and also have it switch your ruby and node.js versions automatically when entering a directory that has a .tool-versions, .ruby-version and/or .node-version file.

bash
# install a ruby version manually
asdf install ruby 2.7.2

What's your setup?

Does your Ruby, Node.js or Python management look different? What's working for you? Find me on twitter @wolfgangrittner, or drop me a mail to me@wolfgangrittner.dev.