Installing and Using NVM (Node Version Manager)
Node Version Manager (NVM) is a powerful tool designed to manage multiple versions of Node.js on a single machine. It simplifies the process of installing, updating, and switching between different versions of Node.js, making it an essential tool for developers working on various projects with different Node.js requirements.
Benefits of Using NVM Copy link
-
Version Management: Easily install and switch between different versions of Node.js.
-
Environment Isolation: Maintain separate Node.js versions for different projects.
-
Convenience: Simplifies testing and development by providing quick version switching.
Installing NVM Copy link
To install NVM, follow these steps:
1. Download and Install Script
Open a terminal and run the following command to download and install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bashOutput:
2. Load NVM
After the installation, you need to add NVM to your shell profile. Run the following command:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"3. Verify Installation
Ensure that NVM is installed correctly by checking its version:
nvm --versionOutput:
Installing Node.js Versions with NVM Copy link
With NVM installed, you can now install different versions of Node.js.
1. Install a Specific Version
To install a specific version of Node.js, use the following command:
nvm install <version>Replace <version> with the desired Node.js version number (e.g., 14.17.0).
Output:
2. Install the Latest LTS Version
To install the latest Long-Term Support (LTS) version of Node.js, run:
nvm install --ltsOutput:
Switching Between Node.js Versions Copy link
NVM allows you to switch between installed Node.js versions easily.
1. List Installed Versions
To view all installed Node.js versions, use:
nvm lsOutput:
2. Switch to a Specific Version
To switch to a specific version, run:
nvm use <version>Replace <version> with the version number you want to use.
Setting a Default Node.js Version Copy link
You can set a default Node.js version that will be used in all new shell sessions.
Set Default Version
To set a default Node.js version, use:
nvm alias default <version>Replace <version> with the desired Node.js version number.
Uninstalling Node.js Versions with NVM Copy link
NVM also provides an easy way to uninstall Node.js versions that are no longer needed.
Uninstall a Specific Version
To uninstall a specific Node.js version, run:
nvm uninstall <version>Replace <version> with the version number you want to uninstall.
Conclusion Copy link
Using NVM (Node Version Manager) simplifies the management of multiple Node.js versions, providing a convenient and efficient workflow for developers. By following the steps outlined in this tutorial, you can easily install, switch, and manage different Node.js versions on your system.
This tutorial provides a comprehensive guide to installing and using NVM, ensuring a smooth and efficient Node.js version management experience.
In addition, our app platform offers a variety of Node.js frameworks, including as Express, Fastify, Hapi and Nest.