Replacing nvm with asdf to manage NodeJS versions

I’ve been using zsh with antigen as the package manager for years. Over time as I add more customizations, I noticed that my shell startup time has become slow. Sometimes, it would take more than 3 seconds to start up.

I read few months (or a year) ago that nvm, a version manager for nodejs can cause this issue so I thought maybe it’s the right time I should try asdf.

asdf is basically just another tool to manage versions but instead of having to install multiple tools like rbenv for ruby or nvm for nodejs, you can just use asdf and use its plugins to manage all the language versions that you’re using.

Anyway, I’m not going to talk about what’s so good about it. For that, you can read the docs yourself. I’m just going to document the steps I did here.

Removing nvm completely

First of all, I have to completely remove nvm. Here are the steps:

1# list out all the nodes version I'm using
2$~ nvm ls
3# uninstall nodejs
4$~ nvm uninstall <NODEJS_VERSION> 
5# uninstall nvm with brew (since I install it using Brew)
6$~ brew uninstall nvm
7# delete related dotfiles and directory
8$~ rm -rf ~/.nvm/ ~/.nvmrc

Installing asdf

Then, I installed asdf using Brew

1# install asdf using Brew
2$~ brew install asdf

Then, I have to add the following in my ~/.zshrc file to load asdf properly.

2# setup asdf
3. /usr/local/opt/asdf/

That basically completes the asdf setup. Next I have to install the nodejs plugin. To install the nodejs plugin, I run the following command:

1$~ asdf plugin-add nodejs # install nodejs plugin
2$~ bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring # import nodejs release team OpenPGP keys

I got an error when trying to import the keys. Apparently, I don’t have gpg2 installed yet so I have to install it first.

1$~ brew install gpg2

After installing gpg2, I can finally run the nodejs installation without any error.

1$~ asdf install nodejs 15.8.0 # install nodejs version 15.8.0
2$~ asdf global nodejs 15.8.0 # set it as the global version

That’s pretty much it. I finally have a working nodejs environment and I notice that my terminal startup time is a little bit faster now. Nice.

I just need to replace rbenv and pyenv next.