I’m a Senior Software Engineer living in Berlin. Shifting limits based on quality and robustness. Cutting-edge software development. Defining durable and flexible interfaces. Creating rich and intuitive user experiences.

Asdf and .tool-versions

Install asdf

asdf is a versatile version manager that supports multiple languages and tools with a single CLI. The following command uses Homebrew to install asdf on macOS, making it easy to manage versions of Node.js, Python, Ruby, and more.

brew install asdf

By default, asdf does not recognize legacy version files like .nvmrc or .node-version. Enabling this setting in your ~/.asdfrc file allows asdf to automatically read and respect these files when determining which Node.js version to use.

echo "legacy_version_file = yes" >> ~/.asdfrc

Install a Node.js version

Before you can install Node.js versions with asdf, you need to add the Node.js plugin. This command pulls the plugin from the official repository so you can install and manage Node versions with ease.

asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git

Once the plugin is added, you can install a specific Node.js version using the asdf install command. The example below installs version 22.18.0.

asdf install nodejs 22.18.0

It’s recommended to install at least the current LTS version for security reasons. You can check the latest LTS versions by visiting the Node.js website here.

Set a global default Node.js version

This command sets the specified Node.js version as the global default, meaning it will be used system-wide unless a local version is specified in a project directory.

asdf set -u nodejs 22.18.0

Bash function to upgrade Node.js versions

The anup function is a handy utility that automatically installs the latest available patch version for a given major Node.js version. It ensures your environment stays current without having to manually look up version numbers.

export ASDF_DATA_DIR="$HOME/.asdf"
export PATH="$ASDF_DATA_DIR/shims:$PATH"
function anup() {
if [ -z "$1" ]; then
echo "usage anup <major version>"
return 1
else
asdf install nodejs "$(asdf list all nodejs $1 | sort --version-sort --reverse | head -1 | xargs)"
fi
}

Usage

To use the function, pass the major version you want to upgrade. For example, anup 22 will install the latest 22.x.x release available. You can verify the installed versions with asdf list.

anup 22
asdf list