[asdf Node.js] Use asdf nodejs plugin to install multiple Node.js versions

asdf and Node.js Plugin

asdf is a single CLI tool for managing multiple runtime versions. It extend with a simple plugin system to install your favourite language: Dart, Elixir, Flutter, Golang (Go), Java, Node.js, Python, Ruby …

This article is about how to use asdf and Node.js plugin to install multiple Node.js versions on macOS with the Homebrew package manager.

Prerequisites

  • Xcode Command Line Tools
    The Xcode Command Line Tools Package is a small self-contained package available for download separately from Xcode and that allows you to do command line development in macOS which is consists of the macOS SDK and command-line tools such as Clang, which are installed at this

    For more information about installing and using Xcode Command Line Tools, see the Xcode Command Line Tools

  • Homebrew
    Homebrew is the Missing Package Manager for macOS (or Linux).

    For more information about installing and using Homebrew, see the Homebrew - https://brew.sh/.

Installation

Install asdf

1
2
3
4
5
# Install asdf dependencies
$ brew install coreutils curl git

# Install asdf
$ brew install asdf

asdf Node.js Plugin

1
2
3
4
5
6
7
8
9
10
11
# Install Node.js plugin requirements
$ brew install openssl readline

# GnuPG
$ brew install gpg

# AWK - any posix compliant implementation (tested on gawk)
$ brew install gawk

# Install Node.js plugin
$ asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git

Add to your Shell

Add asdf.sh to your ~/.zshrc with:

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

Or see Add to your Shell - https://asdf-vm.com/#/core-manage-asdf to learn when you use other shells.

List all Node.js Version

Update Node.js plugin.

1
$ asdf plugin update nodejs

List all Node.js versions.

1
$ asdf list all nodejs

Install Node.js version

Install a Node.js version manually.

1
2
3
4
5
6
7
8
9
10
11
$ asdf install nodejs 14.8.0

$ nodejs version
No version set for command nodejs
Consider adding one of the following versions in your config file at ~/.tool-versions
nodejs 14.8.0

$ echo "nodejs 14.8.0" >> ~/.tool-versions

$ asdf exec node --version
14.8.0

Or install another version.

1
$ asdf install nodejs 14.0.0

FAQs

cat: /usr/local/VERSION: No such file or directory

Add asdf.sh to your ~/.zshrc to resolve it

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

OR see Add to your Shell - https://asdf-vm.com/#/core-manage-asdf to learn when you use other shells.

You must install GnuPG to verify the authenticity of the downloaded archives before continuing with the install: https://www.gnupg.org/

Install GnuPG to resolve it.

1
2
# GnuPG
$ brew install gpg

No preset version installed for command yarn or No yarn executable found for nodejs 16.7.0

1
2
3
4
5
6
7
8
$ yarn -v                                                                   sit  10:23:23
No preset version installed for command yarn
Please install a version by running one of the following:

asdf install nodejs 16.7.0

or add one of the following versions in your config file at /Users/cloudolife/.tool-versions
nodejs 14.8.0

Or

1
2
$ yarn -v
No yarn executable found for nodejs 16.7.0

Check node, yarn status.

1
2
3
4
5
which node                                                                                 10:32:12
/Users/cloudolife/.asdf/shims/node

$ which yarn
/Users/cloudolife/.asdf/shims/yarn

Check yarn reshime shell.

1
2
3
4
5
$ cat /Users/cloudolife/.asdf/shims/yarn
#!/usr/bin/env bash
# asdf-plugin: nodejs 14.8.0
# asdf-plugin: nodejs 16.7.0
exec /usr/local/opt/asdf/bin/asdf exec "yarn" "$@"

Install global yarn.

1
$ npm i -g yarn

References

[1] Manage asdf - https://asdf-vm.com/#/core-manage-asdf

[2] GitHub - asdf-vm/asdf-nodejs: Node.js plugin for asdf version manager - https://github.com/asdf-vm/asdf-nodejs

[3] Home · rbenv/nodejs-build Wiki - https://github.com/rbenv/nodejs-build/wiki#suggested-build-environment

[4] Homebrew - https://brew.sh/

[5] Node.js - https://nodejs.org/en/