
Mastering Node Version Management in Fish Shell (with examples)
Node Version Manager (NVM) is a powerful command-line utility designed to install, uninstall, and switch between different versions of Node.js in the fish shell. It provides users with the flexibility to quickly alternate between versions, whether they’re working on legacy projects or embracing the latest in JavaScript development. With NVM, you can manage versioning seamlessly, ensuring your projects have exactly what they need without any fuss. For additional information, the project’s page can be found here: https://github.com/jorgebucaran/nvm.fish .
Install a Specific Version of Node.js
Code:
nvm install 14.17.0
Motivation: When developing applications, certain projects might require specific Node.js versions to ensure compatibility with certain libraries or features. Installing a specific version allows developers to tailor their environment to meet project specifications, ensuring that their development and production environments are congruent.
Explanation:
nvm: The command to trigger the Node Version Manager.install: A sub-command of nvm used to download and apply the specified Node.js version.14.17.0: The specific version number of Node.js to be installed. It follows the Semantic Versioning (SemVer) structure, which helps ensure developers know the exact characteristics of the installed version.
Example Output:
Installing Node v14.17.0...
Now using Node v14.17.0
Use a Specific Version of Node.js in the Current Shell
Code:
nvm use 16.13.1
Motivation: Switching Node.js versions on-the-fly is crucial when you are working on multiple projects that each depend on different Node.js versions. Using a specific version in the current shell session allows developers to test or run scripts without permanently affecting their default setup.
Explanation:
nvm: The command initiates the Node Version Manager’s functionality.use: A sub-command that selects a Node.js version for the active shell session.16.13.1: This specifies the precise Node.js version to be utilized in the current shell environment.
Example Output:
Now using Node v16.13.1
Set the Default Node.js Version
Code:
set nvm_default_version 12.18.3
Motivation: Setting a default version is particularly useful for defining a baseline Node.js environment whenever a new shell session is started. This becomes crucial in keeping a consistent setup for long-term development, ensuring that subsequent shell logins use the required Node.js version without needing to manually switch each time.
Explanation:
set: A fish shell command that sets environment variables.nvm_default_version: A shell variable recognized by nvm.fish, representing the default Node.js version to be activated when a new shell session begins.12.18.3: The Node.js version number that will be used by default.
Example Output:
nvm_default_version set to 12.18.3
List All Available Node.js Versions and Highlight the Default One
Code:
nvm list
Motivation: Listing all available Node.js versions helps developers quickly view which versions are installed locally and which are set as default. This feature is particularly useful for system audits and ensuring that backups or specific project requirements align with installed versions.
Explanation:
nvm: The command invokes Node Version Manager.list: A sub-command that displays all Node.js versions currently installed on the system, highlighting the default and actively used version.
Example Output:
-> v12.18.3
v14.17.0
default -> 12.18.3
Uninstall a Given Node.js Version
Code:
nvm uninstall 15.5.1
Motivation: Over time, as projects update and requirements change, you may wish to remove obsolete or unused Node.js versions to free up system resources and reduce clutter. Uninstalling non-essential versions helps in maintaining an organized workspace and avoids potential conflicts with other installed versions.
Explanation:
nvm: The command triggers the Node Version Manager’s actions.uninstall: A sub-command designed to remove a specified Node.js version from the system.15.5.1: This specifies the Node.js version targeted for removal.
Example Output:
Uninstalling Node v15.5.1...
Node v15.5.1 has been uninstalled
Conclusion:
NVM is an indispensable tool for developers who need flexibility and precision when working with multiple Node.js versions. Whether installing specific versions, switching contexts, or maintaining an orderly environment, NVM allows for seamless management of Node.js configurations, thereby enhancing productivity and project consistency.

