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.
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.
To install NVM, follow these steps:
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 | bash
Output:
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")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Ensure that NVM is installed correctly by checking its version:
nvm --version
Output:
With NVM installed, you can now install different versions of Node.js.
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:
To install the latest Long-Term Support (LTS) version of Node.js, run:
nvm install --lts
Output:
NVM allows you to switch between installed Node.js versions easily.
To view all installed Node.js versions, use:
nvm ls
Output:
To switch to a specific version, run:
nvm use <version>
Replace <version>
with the version number you want to use.
You can set a default Node.js version that will be used in all new shell sessions.
To set a default Node.js version, use:
nvm alias default <version>
Replace <version>
with the desired Node.js version number.
NVM also provides an easy way to uninstall Node.js versions that are no longer needed.
To uninstall a specific Node.js version, run:
nvm uninstall <version>
Replace <version>
with the version number you want to uninstall.
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.