Home >Web Front-end >JS Tutorial >Installing and Managing Node.js with NVM
In 2025, Node.js will still be an indispensable tool for JavaScript development. This guide not only covers installing Node.js on different platforms, but also provides in-depth information on how to use the Node Version Manager (NVM) to efficiently manage multiple Node.js versions.
NVM (Node Version Manager) is a command line tool that allows developers to easily manage multiple Node.js versions.
NVM is especially useful for projects that require a specific Node.js version, allowing seamless switching between versions and avoiding version conflicts.
Alternative: If you prefer the traditional installation method, you can install it directly from the Node.js official website (https://www.php.cn/link/beddf554eb637cbe8c079b879c79c29b.
On macOS and Linux: Open a terminal and run the installation command:
<code>curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash</code>
Update shell configuration file:
<code>source ~/.bashrc # 对于bash source ~/.zshrc # 对于zsh</code>
Verify installation:
<code>nvm --version</code>
On Windows: Download the nvm-windows installer from GitHub, run the installer and follow the instructions.
Open a new command prompt and verify installation:
<code>nvm version</code>
After installing NVM, you can easily manage different Node.js versions.
Install the latest LTS version:
<code>nvm install --lts</code>
Install a specific version:
<code>nvm install 16.14.0</code>
List installed versions:
<code>nvm ls</code>
Switch between versions:
<code>nvm use 16.14.0</code>
To ensure version consistency of the team project, create a .nvmrc
file in the project root directory:
<code>16.14.0</code>
Any team member can then simply run:
<code>nvm use</code>
For production projects, always use LTS versions. Update NVM to the latest version regularly.
Implement .nvmrc
files across all projects to maintain team consistency.
Back up the global npm configuration before switching versions.
Use npm scripts to automate version switching across environments.
Custom alias:
<code>nvm alias myproject 14.17.0 nvm use myproject</code>
Run the command with a specific version:
<code>nvm exec 14.17.0 node script.js</code>
Install global packages by version:
<code>nvm use 14.17.0 npm install -g yarn</code>
PATH conflict: check your shell profile configuration. Permissions on macOS/Linux:
<code>sudo chown -R $(whoami) ~/.nvm</code>
Performance on Windows: Consider using Windows Subsystem for Linux (WSL) for a Unix-like experience.
In 2025, efficiently using NVM to manage Node.js installations is more important than ever. With the JavaScript ecosystem rapidly evolving, being able to easily switch between Node.js versions and manage multiple development environments is crucial for modern developers. By mastering NVM and following the best practices outlined in this guide, you'll be well-equipped to handle the challenges of contemporary Node.js development, ensuring your project's flexibility and efficiency.
Original article published at https://codeinit.dev/blog/instalacao-e-gerenciamento-do-nodejs-com-nvm
The above is the detailed content of Installing and Managing Node.js with NVM. For more information, please follow other related articles on the PHP Chinese website!