Install and Use asdf Version Manager



If you are a DevOps engineer, a Linux sysadmin, or even just a developer, you may have faced the annoying problem of managing versions in your development environment. Luckily, we now have a tool that can manage this for us out of the box, called ASDF.

ASDF stands out for its ability to install multiple languages and development tools. It advantageously replaces the use of multiple language-specific version managers, such as NVM for Node.js or Pyenv for Python. This greatly simplifies the setup of the development environment, as you only need one tool to manage all your versions.

ASDF allows you to define global or local versions for each project. This ensures that each team member works with the same configuration, thus avoiding problems related to version differences.

In general, ASDF provides a better solution for managing multiple versions of tools and languages, making the life of a developer or sysadmin easier and more efficient.

In this article, we will learn how to install and use this tool on Linux, and we will go through an example of how it can be used in a real-world scenario.

Install ASDF

The installation of ASDF is a simple and direct process, which can be adapted to different operating systems.

Here are the general steps to install ASDF on a Unix-like system, such as Linux or macOS. First of all, clone the GitHub repository of ASDF into your user directory. But make sure you have Git installed on your machine to be able to clone a GitHub repository.

If not, install it first for Ubuntu/Debian/Mint ?

sudo apt install git 

For Red Hat / Fedora:

sudo dnf install 

Now this should install Git on your system, and you are ready to go.

Open your terminal and run the following command ?

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

Now you should configure Bash to use ASDF. For Bash or Zsh users, add the following line to the file ~/.bashrc. In case you use Zsh, add it to the .zshrc file ?

. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"

After adding the necessary line to the bash or zsh use the command source to load the new configuration.

source .bashrc 

Or .zshr for the zsh users.

In case you are using a different environment, you can check the official website of ASDF. There are many ways to install ASDF, depending on the tools that you use.

How to Use ASDF?

After you install ASDF, the usage is very simple and powerful. Let's say, for example, you want to install Node.js on your system.

ASDF uses the term 'plugins' to work with languages and tools. For example, to add a language in this case, Node.js you can use the command ?

asdf plugin add nodejs

This will add Node.js.

To list all installed plugins, use the command ?

asdf plugin list all

To list all the versions of Node.js, use the command.

asdf list all nodejs

To install a specific version, use the command:

asdf install <name> <version>

Example: Node.js 18

asdf install nodejs 18

To install the latest version of a language, use the tag latest:

asdf install nodejs latest

To remove or uninstall a version, use the command:

asdf uninstall <name> <version>

Example: Remove the Node.js version 18:

asdf uninstall nodejs 18

Configuration

ASDF has a file called .tool-versions that helps set a configuration for ASDF. Let's say, for example, a team is working on a specific project and needs to share the same configuration.

Just like in the previous example, suppose we need specific versions of Node.js and Python for this project. We can do that by adding this configuration to the root of our project.

The .tool-versions look like this ?

python 3.0.0
nodejs 18.0

We put the name followed by the specific version that we need.

You can also use this configuration file to set the global default for your user on the system. This file will be located in $HOME/.tool-versions.

Conclusion

ASDF should be one of your daily tools if you are a DevOps engineer or even a developer. It helps a lot in managing versions and tools in an easy and efficient way compared to other tools that we can use. Even if you are a beginner, you can make ASDF work for you because it is easy to use and manage.

This article was an introduction to the ASDF tool and how we can install it on Linux.

Updated on: 2024-11-21T11:35:39+05:30

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements