1. Introduction:
Each language has its own version manager. For Node.js, we use NVM (Node Version Manager), which allows us to work with multiple versions of Node.js in the same environment. This is useful for testing our developments on different versions of Node.js, which is a good practice recommended by both npm and Microsoft.
2. Key Concepts:
• NPM: Node.js Package Manager.
• NVM: Node.js Version Manager.
3. Preparations:
Before installing NVM, we must ensure that there is no previous version of Node.js installed on our system to avoid conflicts. To check this, run in the terminal:
node -v
4. NVM installation:
• For macOS and Linux: Visit the official NVM repository on GitHub (nvm-sh/nvm).
• For Windows: Download NVM from the following link:
5.Verify NVM installation:
Once installed, open a new terminal and verify that NVM is correctly installed by running:
nvm
6.Install a version of Node.js:
NVM allows you to install specific versions of Node.js or the latest version. To install the latest recommended version (LTS), run:
nvm install lts
7.List installed versions of Node.js:
To view the versions of Node.js installed on your system, use:
nvm list
8.Use a specific version of Node.js:
Open a terminal with administrator permissions and choose the version of Node.js you want to use:
nvm use 16.13.1
(Replace 16.13.1 with the version you want.)
9.Check the version of Node.js in use:
To check which version of Node.js is active, run:
node -v
You can also check the current version of Node.js handled by NVM with:
nvm current
10.Uninstall a version of Node.js:
If you want to uninstall a version of Node.js, open the terminal with administrator permissions and run:
nvm uninstall 16.13.1
(Replace 16.13.1 with the version you want to remove.)
11.Installing NPM and Yarn:
When you install Node.js with NVM, npm is installed automatically. To check the npm version, use:
npm -v
If you prefer to use Yarn, install it for each version of Node.js you use:
npm install -g yarn
Conclusion:
With NVM, you can easily manage multiple versions of Node.js on a single system, allowing you to easily test in different environments.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3