Version Management — asdf

Satvik Goyal
ScaleReal
Published in
6 min readJul 9, 2024

Hello folks I hope you all are doing well! In this article, we are going to see asdf. With asdf, developers can easily install and switch between different versions of a language and manage dependencies for each version.

At ScaleReal we work extensively on Python/Django Applications and have built many highly scalable applications for our various clients.

Here’s a list of everything which will be covered in this article:

  1. What is asdf?
  2. Why do we need asdf?
  3. How to install asdf?
  4. Install multiple versions of Python using asdf
  5. Helpful asdf commands
  6. Troubleshooting

What is asdf?

asdf is a version manager tool that allows developers to manage multiple runtime versions of various programming languages and tools. It stands for “Abstract Scripting Definition Format” and provides a unified interface for installing, managing, and switching between different versions of languages and tools on a single development machine.

Why do we need asdf?

  1. Multiple version management: Asdf allows developers to easily manage multiple versions of a programming language or dependency on a single system. This is particularly useful for developers who need to work with multiple projects that may have different version requirements, or for those who want to easily switch between different versions of a language for testing or development purposes.
  2. Consistent environment: Asdf provides a consistent environment for different projects, regardless of the versions of the programming languages or dependencies they use. This helps ensure that each project runs as expected, and it eliminates the risk of version conflicts between different projects.
  3. Improved efficiency: Asdf eliminates the need for manual installation or the use of virtual environments. With asdf, developers can easily install and switch between different versions of a language or dependency with a single command.
  4. Flexibility: Asdf allows for the use of plugins to manage dependencies for specific languages. This makes it easy for developers to manage dependencies for a wide range of programming languages and frameworks with a single tool.
  5. Improved organization: Asdf provides a clean and organized way to manage different versions of software on a single system. This makes it easier for developers to keep track of the software they have installed, and it eliminates the risk of software version conflicts.

How to install asdf?

  1. Installation on macOS:
  • Open Terminal and run the following command:
brew install asdf

if using ZSH:

echo -e "\\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

if using bash:

Add the following to ~/.bash_profile:

. "$HOME/.asdf/asdf.sh"

Completions must be configured manually with the following entry in your .bash_profile:

. "$HOME/.asdf/completions/asdf.bash"
  1. Installation on Linux:
  • On Ubuntu/Debian, run the following command in Terminal:
sudo apt-get update
sudo apt-get install -y automake autoconf libreadline-dev libncurses-dev libssl-dev libyaml-dev libxslt-dev libffi-dev libtool unixodbc-dev
  • Then, download the asdf repository to your machine:
git clone <https://github.com/asdf-vm/asdf.git> ~/.asdf --branch v0.14.0
  • Add the asdf initialization to your shell profile:
echo -e '\\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo -e '\\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
  1. Installation on Windows:
  • Install Git Bash and run the following command in the Git Bash terminal:
git clone <https://github.com/asdf-vm/asdf.git> ~/.asdf --branch v0.14.0
  • Add the asdf initialization to your shell profile:
echo -e '\\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo -e '\\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc

Once you have installed asdf, you can start using it to manage different versions of programming languages and dependencies. To do this, you will need to install plugins for the languages you want to use, and then use the asdf command line to install and switch between different versions.

Install multiple versions of Python with asdf

  • To install multiple versions of Python using asdf and manage them, follow these steps:
  • Install the python plugin by running the following command:
asdf plugin-add python
  • Use the following command to install a specific version of Python:
asdf install python <version>
  • For example, if you want to install Python 3.8 and Python 3.9, you would run:
asdf install python 3.8.0
asdf install python 3.9.0
  • Use the following command to list all installed versions of Python:
asdf list python
  • Use the following command to set a specific version of Python as the global version:
asdf global python <version>
  • For example, if you have installed Python 3.8 and Python 3.9, and you want to set Python 3.8 as the global version, you would run:
asdf global python 3.8.0
  • With these steps, you can easily install multiple versions of Python and switch between them as needed. Additionally, you can install and manage packages for each version of Python independently, without affecting packages installed for other versions.

Install multiple versions of Node with asdf

You can view a list of Node versions with the following:

asdf list all nodejs | wc -l   # prints 735

To install a specific version of Node, run this:

asdf install nodejs 22.1.0

You can see which versions you have installed by running the following:

asdf list all nodejs

To install the latest version of Node, run:

asdf install nodejs latest

⭐Helpful asdf commands

  1. asdf plugin-list: List all installed plugins.
  2. asdf plugin-add <plugin-name>: Install a new plugin.
  3. asdf plugin-update <plugin-name>: Update an existing plugin.
  4. asdf plugin-remove <plugin-name>: Remove an existing plugin.
  5. asdf list <language-name>: List all installed versions of a language.
  6. asdf install <language-name> <version>: Install a specific version of a language.
  7. asdf uninstall <language-name> <version>: Uninstall a specific version of a language.
  8. asdf local <language-name> <version>: Set the local version of a language for the current project.
  9. asdf global <language-name> <version>: Set the global version of a language.
  10. asdf exec <language-name> <command>: Run a command with a specific version of a language.
  11. asdf reshim <language-name> <version>: Re-create the shim for a specific version of a language.
  12. asdf current <language-name>: Show the current version of a language.
  • These commands should give you a good start in using asdf to manage different programming languages and their versions.

Troubleshooting:

  1. Error when adding a plugin: If you encounter an error when adding a plugin, make sure your system meets the prerequisites for that plugin, such as having the required dependencies installed. If you still encounter an error, try removing and re-installing the plugin.
  2. Error when installing a language version: If you encounter an error when installing a language version, ensure the version is supported by the plugin you are using. If you are installing a version that is not yet supported, try installing an earlier version that is supported.
  3. Error when switching between versions: If you encounter an error when switching between versions, make sure that you have installed the version you want to switch to, and that it is set as the global version. If the issue persists, try re-creating the shim for that version.
  4. Error when executing a command: If you encounter an error when executing a command with a specific version of a language, make sure that you have the correct version of the language installed and set as the global version. If the issue persists, try re-creating the shim for that version.
  5. Conflicts with other version managers: If you have previously installed a different version manager, such as rbenv or pyenv, you may encounter conflicts with asdf. To resolve these conflicts, make sure you have uninstalled the other version manager, or have set the correct environment variables to use asdf.

At Scalereal We believe in Sharing and Open Source. Thanks for reading! If you enjoyed reading this article, please click the 👏 button and share it with everyone. Feel free to leave a comment 💬 below.

Sharing is Caring! Thank You :) 🙏

If you need any help, you can contact me on LinkedIn or Github.

~Satvik Goyal

--

--