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
π«Ά.
asdfis 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.
But why do we have to use this? Doesnβt each language have its tool version manager?
asdfmeans 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β
| git | git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2 |
|---|---|
| Homebrew | brew install asdf |
Install asdfβ
Bash & Git:
echo ". $HOME/.asdf/asdf.sh" >> ~/.bashrc
echo ". $HOME/.asdf/completions/asdf.bash" >> ~/.bashrc
Install pluginsβ
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:
| OS | Dependency 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:
| OS | Dependency 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
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
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 .