Skip to main content

Tool Version Manager

Manage our package versions is relatively tricky, NodeJS has its nvm, Python with pyenv, or Go with goenv. How about a central tool version manager?

Luckily, I stumbled upon a tool that perfectly fits my needs: asdf-vm a.k.a asdf, which will handle all my favorite packages with a single CLI tool, same experience but fewer installation steps 🫢.

asdf is a tool version manager. All tool version definitions are contained within one file (.tool-versions) which you can check in to your project's Git repository to share with your team, ensuring everyone is using the exact same versions of tools.

asdf has Elixir, Erlang, NodeJS, or Ruby as first-party plugins. However, its support is very generous, which comes from community plugins, i.e., asdf-community, a collaborative, community-driven project for long-term maintenance of asdf plugins.

note

But why do we have to use this? Doesn’t each language have its tool version manager?

  • asdf means to be a central tool, which replaces other tools’ complexity with simpler and easy to use commands.

Getting Started​

Install dependencies​

sudo apt install curl git

Download asdf​

gitgit clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2
Homebrewbrew install asdf

Install asdf​

Bash & Git:

echo ". $HOME/.asdf/asdf.sh" >> ~/.bashrc
echo ". $HOME/.asdf/completions/asdf.bash" >> ~/.bashrc

Install plugins​

info

Each plugin has dependencies so we need to check the plugin repo where they should be listed.

asdf-nodejs​

Use node-build under the hood

Dependencies:

OSDependency Installation
Linux (Debian)apt-get install dirmngr gpg curl gawk

Install the plugin:

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

asdf-python​

Use python-build (from pyenv) under the hood

Dependencies:

OSDependency Installation
Linux (Debian)apt-get install make build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

Install the plugin:

asdf plugin-add python
info

If you still have problems, each plugin might be built on a specific package, (e.g., asdf-nodejs utilizes node-build or asdf-python uses python-build under the hood), you can go to that package and find solutions.

Install a version​

asdf-nodejs​

asdf install nodejs latest
info

asdf enforces exact versions. latest is a helper throughout asdf that will resolve to the actual version number at the time of execution.

asdf-python​

asdf install python 3.9.13

Set a version​

Global​

Global defaults are managed in $HOME/.tool-versions. Set a global version with:

asdf-nodejs​
asdf global nodejs latest
asdf-python​
asdf global python 3.9.13

Local​

Local versions are defined in the $PWD/.tool-versions file (your current working directory). Usually, this will be the Git repository for a project. When in your desired directory execute:

asdf-nodejs​
asdf local nodejs latest

$PWD/.tool-versions will then look like this:

nodejs 18.9.1
asdf-python​
asdf local python 3.9.13

$PWD/.tool-versions will then look like this:

python 3.9.13

Then you can easily install all dependencies with this command, just like Yarn or npm or Pnpm:

asdf install

Going further with Nix​

asdf is great, but Nix is much better, it has a big ecosystem with a thousand packages managed by nixpkgs, a Linux distribution NixOS, or even Nix programming language!

However, NixOS has a steep learning curve and is quite hard to get comfortable with for the first time, like its garbage collector or Flakes.

So it will take time and more research to bring Nix into action. Stay tuned .