DEV Community

Cover image for asdf - Manage multiple runtime versions
Pavel Kutáč
Pavel Kutáč

Posted on

asdf - Manage multiple runtime versions

Tool called asdf is a simple CLI tool for managing multiple runtime or tool versions. You can switch them whenever is needed or assign different versions for different folders or projects.

🇨🇿 V češtině si lze článek přečíst na

There are package managers like apt, snap, DNF, and many more, based on the distribution. However, those managers very often replace the old package version with a new one. And very often automatically.

How asdf can help is visible in the picture below. When I switched to a different folder, the node command runs a different version of NodeJS.

Preview of asdf with global and local versions

Installation and updates directly from git

Even asdf can be very handy and useful, it is very easy to install. The whole process consists of 3 steps and is well described in It is enough to have installed curl and git and asdf can be installed just by git clone and integrating into the Shell. The update is done simply by asdf update and uninstalling by removing asdf directory.

asdf is supported with Bash, Fish, and ZSH.

All is about plugins

The pure installation of asdf cannot do much. And because of that, there are plugins. Every plugin is specialized for 1 runtime or tool. There are plugins for NodeJS, Ruby, Elixir, PHP, Python. But also C#, .NET Core, Java. And tools like 1Password, GCloud, or SQLite. There are more than 250 plugins already.

Step By Step - NodeJS with asdf

When asdf is installed and integrated into the Shell, it is possible to run some asdf command described below.

# Prints current versions of runtimes/tools for current directory
# But now prints: Oohes nooes ~! No plugins installed 
asdf current 
# Lets install NodeJS plugin
asdf plugin-add nodejs
# Now current produce different output
# nodejs   ______   No version set. Run "asdf <global|shell|local> nodejs <version>"
asdf current
Enter fullscreen mode Exit fullscreen mode

Now it is possible to install a concrete version of NodeJS. However, plugins can have some prerequisites as well. Check Readme of NodeJS plugin to asdf and add PGP keys. Now we are ready to continue.

# List all available versions for NodeJS
asdf list all nodejs
# Install selected version of NodeJS
asdf install nodejs 15.5.0
# Activate same version globally 
asdf global nodejs 15.5.0
Enter fullscreen mode Exit fullscreen mode

It is possible to repeat the last 3 steps again and again with a different version. And instead of asdf global we can use asdf local to activate a specific version only for the current directory. It will also create .tool-versions, which can be shared via git and all co-workers will use the same versions always.

Top comments (0)