DEV Community

Cover image for The Ultimate Guide to Node.js Version Managers: NVM, NVS, fnm, Volta, and asdf | Part 3
Erik Harutyunyan
Erik Harutyunyan

Posted on

The Ultimate Guide to Node.js Version Managers: NVM, NVS, fnm, Volta, and asdf | Part 3

asdf

asdf is a version manager that aims to be a “universal language version manager.” Created by Jean-Louis Reynaud in 2015, it supports a wide variety of programming languages and tools, including Node.js. It is designed to be easily extendable as new languages and tools are introduced.

asdf currently supports Node.js, Ruby, Python, Elixir, Java, Rust, PHP, Perl, Haskell, R, Lua, and Erlang. For all of these languages, you can manage different versions in one place via a single .tool-versions configuration file. This file can be included in your project repository so that the entire team uses the same versions of the tools.

How to Install and Use

Dependencies required for asdf:

First, we need to install some dependencies like coreutils, curl, and git. These dependencies are used by asdf to manage different language versions.

macOS:

  • Homebrew:
brew install coreutils curl git
Enter fullscreen mode Exit fullscreen mode
  • Spack:
spack install coreutils curl git
Enter fullscreen mode Exit fullscreen mode

Linux:

sudo apt install curl git
Enter fullscreen mode Exit fullscreen mode

Installationon macOS and Linux:
Installation via Git:

Open the terminal and run the following command:

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.13.1
Enter fullscreen mode Exit fullscreen mode

Or install via Homebrew (only for macOS):

brew install asdf
Enter fullscreen mode Exit fullscreen mode

Shell Configuration: Add the following lines to your shell configuration file (e.g., ~/.bashrc or ~/.zshrc):

  • Bash/Zsh:
. $HOME/.asdf/asdf.sh
Enter fullscreen mode Exit fullscreen mode
. $HOME/.asdf/completions/asdf.bash
Enter fullscreen mode Exit fullscreen mode

Then apply the changes with:

source `~/.bashrc`
Enter fullscreen mode Exit fullscreen mode
source `~/.zshrc`
Enter fullscreen mode Exit fullscreen mode

Installation for Windows:
To install asdf on Windows, use the Windows Subsystem for Linux (WSL):

  1. Set up WSL: Install and set up WSL on your system using the Microsoft guide.
  2. Install asdf in WSL: Follow the installation instructions for asdf for Linux, as described above.

After setting up asdf in your shell configuration, plugins are installed to manage specific tools. When a tool is installed, shims (proxy files) are created, which intercept calls to executables, determine the tool version from .tool-versions, and execute the corresponding version.

Using asdf:

  • List all available plugins: asdf plugin list all
  • Add a plugin: asdf plugin add nodejs
  • List installed plugins: asdf plugin list
  • Remove a plugin: asdf plugin remove nodejs
  • Update a plugin: asdf plugin update nodejs
  • Update all plugins: asdf plugin update --all
  • Install a specific version or starting with a certain number of Node.js: asdf install nodejs 16.13.0 or asdf install nodejs latest:18
  • Install the latest available version: asdf install nodejs latest
  • Set the global version (default): asdf global nodejs 16.13.0
  • Set the version for the current project: asdf local nodejs 16.13.0
  • Remove a version of Node.js: asdf uninstall nodejs 16.13.0
  • View installed versions of Node.js: asdf list nodejs
  • View all available Node.js versions: asdf list all nodejs
  • Install versions from the .tool-versions file: asdf install
  • Show the current active version of Node.js: asdf current nodejs

.tool-versions Configuration File:

  • What it is: .tool-versions is a text file in the project's root directory that defines the versions of all tools used in the project.
  • Why it’s needed: Ensures that all team members use the same tool versions, simplifies environment setup, and prevents version conflicts.

Example content of the **.tool-versions** file:

nodejs 16.13.0
Enter fullscreen mode Exit fullscreen mode

Advantages of asdf:

  • Versatility: Manage versions of various languages and tools with a single manager (one CLI).
  • Uniform commands: Using the same commands for all tools simplifies work and reduces the need to learn different commands.
  • Single configuration file: All tool versions for a project are specified in a single .tool-versions file, simplifying collaboration and preventing version conflicts.
  • Ease of migration: Supports existing configuration files like .nvmrc, .node-version, .ruby-version, making it easier to transition from other version managers.
  • Automatic version switching: asdf automatically switches tool versions based on the current directory.
  • Extensibility through plugins: Ability to add support for new languages and tools through plugins.
  • Autocompletion for shells: Supports autocompletion for popular shells (Bash, Zsh, Fish, Elvish).

Disadvantages of asdf:

  • Limited dependency support: Does not manage system package dependencies; requires manual installation.
  • Complex setup for beginners: Can be difficult to set up and integrate with the shell for beginners.
  • Low performance in some cases: Using shims can sometimes be slower than directly running tools.
  • Not suitable for all scenarios: Not always optimal for system tools or specific scenarios.
  • Less popular: Less known than specialized version managers, which can make it harder to find documentation and support.

Another tool quite similar to asdf is vfox. It supports version management for various programming languages. It also has an MSI installer, unlike asdf, and hence is painless to install for the majority of Windows users. In fact, the function is quite similar to asdf in that it supports Node.js versions by simply changing a configuration.

Image description

Comparing Node.js Version Management Tools

Selection of a tool that manages the version of Node.js requires considering every factor affecting performance, speed, and usability. Given below is a detailed comparison of key tools based on several factors:

Performance and Speed:

  • NVM: A reliable and flexible tool, but it can be slower when frequently switching versions due to using shell scripts. Suitable for most developers, especially if delays are not critical.
  • NVS: Provides good performance for managing Node.js versions in cross-platform environments. Its speed may be lower than tools written in faster languages, but it effectively handles the task and supports automatic version switching.
  • fnm: One of the fastest tools due to its Rust implementation. Provides instant version switching, making it ideal for large projects and developers who frequently change Node.js versions.
  • Volta: Automatically manages versions, saving time on setup and switching. An ideal choice for teams where automation and version consistency are important.
  • asdf: A universal tool for managing versions of many programming languages and tools. Suitable for multi-language projects, but may be slower and harder to set up for working only with Node.js.

Ease of Use:

  • NVM: Intuitive and easy to use, especially for beginners. Supports most operating systems and provides many useful commands for version management.
  • NVS: Convenient for experienced users thanks to support for automatic version switching and an interactive menu. However, beginners may need time to master the commands.
  • fnm: Provides high performance and is convenient for frequent version switching. Suitable for those who value speed and minimal response time.
  • Volta: Maximally simplifies version management through automation, reducing the likelihood of errors and saving time. Ideal for teamwork and process automation.
  • asdf: Suitable for developers working with multiple programming languages. Allows managing versions of different environments and tools through a single interface but requires more time to set up.

Conclusion

Version management of Node.js is one of the most common tasks that almost every developer does, whether it is supporting numerous projects or testing new features. Each tool here has its own advantages and disadvantages, so the decision about which tool to use will depend upon project and team needs.

Recommendations

  • NVM: Ideal for beginners and those looking for simplicity and flexibility. Provides convenient Node.js version management with a wide range of features.
  • NVS: Suitable for developers who need flexible Node.js version management in different environments. It is a good choice for working with multiple versions or forks, although it is not as fast as some alternatives.
  • fnm: Recommended for developers who value speed and performance. Due to its Rust implementation, fnm provides fast version switching. Suitable for those who frequently switch versions and work in a cross-platform environment.
  • Volta: Suitable for those who value automation and teamwork. This tool automatically manages Node.js versions for each project, saving time and reducing the risk of errors. Ideal for teams working on large projects where version consistency is important.
  • asdf: The best choice for developers working on multi-language projects. Its versatility and support for multiple languages make it convenient for diverse tasks. Suitable for those working with different programming languages and tools but requires a bit more time to set up.

No matter which of them to use, version management with Node.js is just such an important part of modern development that allows one to keep their applications stable and secure, with their performance optimized. Choose the tool that best fits your needs and your style.

The choice is yours! Depending on how you organize your work, each of these tools can become your faithful helper in managing Node.js versions.

Links to Additional Resources and Documentation

You can learn more about and decide on a Node.js version manager by following the official documentation and resources listed below:

These resources will give you a much better understanding of what each tool can do and help you select the right version management method.

Prev to Part 2

Top comments (0)