LEARNNode CLI Automation

Node.js with asdf

They are a couple of good version managers available for Node.js. One of them is asdf. It is an extendable version manager with support for Ruby, Elixir, Node.js, and many more.

Unfortunately, asdf is only available for macOS and Linux. So if you are a Windows user, you might have to look for something else. Let’s take a look at how we can set it up on our computer.

→ STEP #1

The first step is to install it. Since I am a macOS user, I am going to follow its macOS installation guide. You can find this guide here.

I am a Homebrew user so I am going to copy-paste the following in my terminal and press the Enter key.

brew install coreutils curl git

This will install all the required dependencies I need to run asdf on my computer. Now copy-paste the following command and run it in your terminal to install asdf.

brew install asdf

→ STEP #2

Once you have completed the step 1, you would need to add some bash scripts in your ~/.bash_profile. You can copy-paste this script from below.

echo -e "\n. $(brew --prefix asdf)/asdf.sh" >> ~/.bash_profile

And after adding the above script, add this one too.

echo -e "\n. $(brew --prefix asdf)/etc/bash_completion.d/asdf.bash" >> ~/.bash_profile

→ STEP #3

As I told you earlier, asdf has support for many other languages. To install its Node.js plugin, run the following command in your terminal.

asdf plugin-add nodejs [https://github.com/asdf-vm/asdf-nodejs.git](https://github.com/asdf-vm/asdf-nodejs.git)

Now run this command to import the Node.js release team's OpenPGP keys to the main keyring.

bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring'

And you are done. You have successfully setup asdf on your computer. Now you can use it to version control Node.js. If you are interested in reading more about asdf Node.js plugin then you can find it here.

Wrapping Up

asdf is a good version control manager for Node.js but it has one disadvantage. It makes your terminal a little bit slow. If you remember from step #2, you added two scripts in your bash_profile. These scripts make asdf run every time a new terminal is opened. If you don’t mind it then you should definitely give it a shot.

Posted by Saad (It's a work in progress: Needs copy editing review by Awais.)