Polyglot Version Management with asdf
Tags: shell, linux, bash, tutorial
Published: 2020-06-25 18:01:28

---
title: Polyglot Version Management with asdf
published: true
date: 2020-06-25 00:00:00 UTC
tags: shell, linux, bash, tutorial
canonical_url: https://elliotdenolf.com/posts/polyglot-version-management-with-asdf
---

> Originally published on my blog at [elliotdenolf.com](https://elliotdenolf.com/posts/polyglot-version-management-with-asdf)

Dabbling in multiple programming languages can be a lot of fun. However, because each language tends to have its own version manager, remembering each version manager's commands can get a little cumbersome. This is why the idea of having a single version manager for _all_ of your languages is very intriguing. [Asdf](https://asdf-vm.com/) is a version manager that aims to do that. It supports a large number of languages, all with only one set of commands to remember.

Let's get it installed, add a language plugin, then activate the desired language version.

## Installation

Installation is performed using either Homebrew on macOS or Git on Linux.

```bash
# macOS
> brew install asdf
# Linux
> git clone https://github.com/asdf-vm/asdf.git ~/.asdf
```

You must then source the script by adding the following line to your `~/.zshrc`, `~/.bashrc`, or `~/.bash_profile`.

```bash
. ~/.asdf/asdf.sh
```

_See the [latest documentation](https://asdf-vm.com/) if more detail is needed._

## Usage

Asdf has the concept of "plugins" for each supported language. We need to install a plugin for any language we want to use.

First, let's list all available plugins using `asdf plugin-list-all`.

```bash
> asdf plugin-list-all
golang          https://github.com/kennyp/asdf-golang.git
nodejs          https://github.com/asdf-vm/asdf-nodejs.git
python          https://github.com/danhper/asdf-python.git
ruby            https://github.com/asdf-vm/asdf-ruby.git
# many more...
```

From the list, let's add the Node.js plugin.

```bash
> asdf plugin-add nodejs
```

Once the plugin is added, we can list all versions available to us.

```bash
> asdf list-all nodejs
12.16.0
12.16.1
12.16.2
12.16.3
12.17.0
12.18.0
12.18.1
# many more...
```

Any version from the list can be installed, we'll install the latest LTS.

```bash
> asdf install nodejs 12.18.1
```

Once installed, we declare this version as the one we'd like to use globally on our system.

```bash
> asdf global nodejs 12.18.1
```

If you need to run a specific version _only_ for a single project, we can do that using the `asdf local` command.

```bash
> cd node-10-project
> asdf local nodejs 10.21.0
```

This will create a file named `.tool-versions` that specifies which version should be used within the current project. Asdf will automatically detect and use that version if it is installed.

The above steps can be repeated for any language we'd like.

All plugins and versions installed can be viewed with the `asdf list` command.

```bash
> asdf list
golang
  1.14
  1.15beta1
nodejs
  10.20.0
  12.18.1
python
  3.8.2
  3.10-dev
ruby
  2.7.0
  2.8.0-dev
```

## Summary

Asdf is a very powerful tool that can replace aany number of version managers. I'd highly recommend using it if you use more than a couple languages on your system and have a need to switch between versions. Head on over to their [documentation](https://asdf-vm.com/) if you'd like to learn more.

### Links

- [asdf Documentation](https://asdf-vm.com/)