~/blog|
Published on

Nvm alternative for Node.js version management with asdf

Authors

This article will go through basic asdf configuration for Node.js, including how asdf can read from existing .nvmrc files.

Why switch from nvm?

Multiple language support

asdf supports multiple langauges. This allows me to learn one version manager for all of them. Every languages has their own preferred language manager, and they all vary slightly. Learning a single version manager and its commands just makes sense

Automatically change versions for current directory

asdf automatically changes node version based upon a directory's .tool-versions or .nvmrc (with configuration). Though this can be done with nvm in conjuction with some additional bash scripting. I found the solution rather cumbersome, and the actual usage introduces quite a bit of latency when changing into a directory and the script running nvm use in the background.

With asdf, this all goes away, and it just works and is instant.

Installation

Install using homebrew

brew install asdf

Install the nodejs plugin

asdf plugin add nodejs

Install a node version

To view all available versions using this command

asdf list all nodejs

Choose a specific version or use the lts/latest aliases

asdf install nodejs latest
asdf global nodejs latest

Configuration

Allow asdf to read .nvmrc files

echo 'legacy_version_file = yes' > ~/.asdfrc

Configure yarn for global packages with asdf

yarn config set prefix ~/.yarn

This will let yarn know where to find global packages that were installed with asdf.

Completions

Completions can be installed using this plugin.

There is also an oh-my-zsh plugin available.