One of the most annoying aspects of working on multiple projects as a developer is dealing with projects that use different versions of the same programming language. If you’re a NodeJS developer, you’ve probably used NVM to cope with this. In fact, most programming languages have their own solution to this problem.

However, when you’re working across multiple projects that span multiple programming languagues, using a different version management tool for each language can be cumbersome. That’s where asdf comes in. asdf allows you to install and switch between versions of programming languages with ease. If you’re using Linux, WSL, or MacOS, I highly recommend you check out asdf!

Installation

Installation is simple - just clone the repository and update your PATH variable. You can find the installation instructions here: asdf-vm.com/guide/getting-started.

Adding Common Plugins

The first step is telling asdf what programming languages you’ll be working with. This is done by installing the corresponding plugin for that language. Without the plugins, you won’t be able to install a programming language.

Simply use the command asdf plugin add <plugin name> <git url> to add a plugin. For many common plugins, the url can be omitted. Here’s a selection of some common plugins:

asdf plugin add golang
asdf plugin add nodejs
asdf plugin add python
asdf plugin add java
asdf plugin add rust
asdf plugin add lua

Installing A Language Version

Now, you can install versions of programming languages with the asdf install <language> <version>. To install the latest version of a language, you can simply put latest instead of a specific version. Here are the commands necessary to install the latest versions of the programming languages we mentioned above:

asdf install golang latest
asdf install nodejs latest
asdf install python latest
asdf install java latest
asdf install rust latest
asdf install lua latest

Using a Language Version

Now that you have the language you want installed, the last step is to tell asdf that you want to use that specific version. You can do this via the command asdf global <language> <version>. Again, for the above programming languages these are the commands necessary:

asdf global golang latest
asdf global nodejs latest
asdf global python latest
asdf global java latest
asdf global rust latest
asdf global lua latest

You can switch to a new version by installing it and using asdf global again!

Setting Local Versions

Switching between versions globally is pretty cool, but oftentimes we want to specify a specific version of a programming language in a specific project/directory. Rather than using the asdf global command, we can use asdf local to specify that in the current directory, asdf should use the local version instead of the global version. The local version is specified in the file $PWD/.tool-versions.

Conclusion

Now, you’ve got an easy way to manage installations of your favourite programming languages! You can learn more about asdf at their official website: asdf-vm.com.