asdf: Manage all runtime versions with one tool

A Developer πŸ˜€
3 min readJul 17, 2023

--

Introduction

asdf is a tool version manager. All tool version definitions are contained within one file (.tool-versions) which one check-in in the project repository to share with the team. It will ensure that everyone is using identical versions of tools.

asdf provides a single interface and configuration file to simplify development, and workflows and can be extended to all tools and runtime via a simple plugin interface.

Main Features

  1. single CLI for multiple languages
  2. consistent commands to manage all your languages
  3. single global config keeping defaults in one place
  4. single .tool-versions config per project
  5. support for existing config files like .node-versions, .nvmrc, etc. for easy migration
  6. automatically switching runtime versions as one traverses directories
  7. simple plugin system to add support for the language of choice
  8. shell completion is also available for standard shells like bash, zsh, fish, etc.

Why asdf

asdf ensures teams are using the exact versions of tools, with support for many tools via the plugin system, and the simplicity and familiarity of being a single shell script one can include in the shell configuration.

Working Mechanism

Once asdf core is set up with shell configuration, plugins are installed to manage particular tools. When a tool is installed by a plugin, the executables that are installed have shims created for each of them. When one tries and runs one of these executables, the shim is run instead, allowing asdf to identify which version of the tool is set in .tool-versions and execute that version.

Installing & Configuring

Pre-requisites

  1. Using Homebrew as a package manager, install GIT and Curl.
brew install curl git

2. Download asdf

This is the official download (recommended one)

git clone https://github.com/asdf-vm/asdf.git ~/.asdf

if there is a need for a specific version of asdf, use β€” branch argument along with the specific version (e.g. v0.12.0)

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.12.0

Installation asdf

  1. Execute the following command to complete the installation process
echo 'export PATH="$HOME/.asdf/bin:$HOME/.asdf/shimes:$PATH"' >> ~/.zshrc

Installing & Verifying Node Plugin

  1. As asdf is plugin based tool manager, there is always a requirement to install tool based plugin, in our case it's NodeJs
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git

2. Installing specific node versions can be done at 2 levels:

Project Level (Recommended): Navigate to the project root folder containing the .tool-versions file and execute the following command. This will install the same version of nodeJs as defined in the .tool-version file.

asdf install nodejs

Machine Level: To install the version required in the project at the machine level, then navigate to the HOME directory, and execute the following command with the version mentioned in the .tool-version file present inside the project repository

asdf global install nodejs [VERSION]

e.g: asdf install nodejs 18.13.0

3. Verification: After all the above steps, execute the following command to verify the installation of desired nodeJs version and yarn on the machine

node --version

yarn -v

List all the installed plugins

Execute the following command to list plugins registered on asdf plugins repository with URLs

asdf plugin list all

Conclusion

It's now possible to maintain several versions of the same package on the development machine both at the global and local levels. It will allow developers to use the same version of the packages in different project workspaces.

Happy Coding :)

--

--

A Developer πŸ˜€
A Developer πŸ˜€

Written by A Developer πŸ˜€

Reader | Traveller | Freelancer | Android & Fullstack Developer | Open-Source Enthusiast | Loves Automation

No responses yet