Manage Node.js versions with NVM (Node Version Manager)
Step 1: Install NVM
NVM is a tool for installing and managing different versions of Node.js. First, you need to make sure that NVM is installed on your system. You can check whether NVM is installed with the following command:
nvm --version
If you get the NVM version information, then NVM has been installed successfully.
Step 2: Install the Node.js version
After installing NVM, you can use the NVM command to install different Node.js versions. The following are some commonly used NVM commands:
- Install the latest version of Node.js:
nvm install node
- Install a specific version of Node.js, for example v14.17.0:
nvm install 14.17.0
- To switch between using a different Node.js version:
nvm use 14.17.0
Step 3: Set the default Node.js version
If you want to set a certain Node.js version as the default, after using nvm use
the command, you can use the following command:
nvm alias default 14.17.0
This way, whenever a new terminal window is opened, NVM will automatically use the default Node.js version.
Step 4: Check the installed version
You can check the installed version of Node.js with the following command:
nvm ls
This command will display all installed versions of Node.js and mark the version currently in use.
Step 5: Upgrade the Node.js version
If you want to upgrade the installed version of Node.js to the latest version, you can use the following command:
nvm install node --reinstall-packages-from=14.17.0
This will install the latest version of Node.js and reinstall global packages from older versions.
Hope this blog can help you! Using NVM makes it easy to manage and switch between different Node.js versions to suit project needs. If you have any questions, please continue to communicate.