In 2025, Node.js remains an essential tool for JavaScript development. This detailed guide covers not only installing Node.js on different platforms but also advanced usage of Node Version Manager (NVM) for efficient management of multiple versions.
What is NVM?
NVM (Node Version Manager) is a command-line tool that allows developers to manage multiple versions of Node.js easily.
Key Features of NVM:
- Enables installation, switching, and removal of different Node.js versions on a single machine.
- Provides a simple interface for managing Node.js versions via terminal commands.
- Allows running multiple Node.js versions on the same computer.
- Facilitates switching between Node.js versions for different projects, avoiding compatibility issues.
- Also manages npm (Node Package Manager) installations corresponding to each Node.js version.
- Works on Unix systems, macOS, and Windows (via WSL).
NVM is particularly useful for developers working on projects that require specific Node.js versions, allowing seamless switching between them and avoiding version conflicts.
Alternative Note: If you prefer a traditional installation, you can download the official installer directly from the Node.js website at https://nodejs.org, where you will find specific versions for each operating system with pre-configured installers.
Installing NVM
On macOS and Linux:
Open the terminal and run the installation command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Update the shell profile:
source ~/.bashrc # For bash
source ~/.zshrc # For zsh
Verify the installation:
nvm --version
On Windows:
Download the nvm-windows installer from GitHub, run the installer, and follow the instructions.
Open a new command prompt and verify the installation:
nvm version
Installing Node.js with NVM
After installing NVM, you can easily manage different Node.js versions.
Installing the latest LTS version:
nvm install --lts
Installing a specific version:
nvm install 16.14.0
Listing installed versions:
nvm ls
Switching between versions:
nvm use 16.14.0
Advanced Configuration for Projects
To ensure consistency in team projects, create an .nvmrc
file in the project root:
16.14.0
Then, any team member can simply run:
nvm use
Tips and Best Practices
Always use the LTS version for production projects. Regularly update NVM to the latest version.
Implement .nvmrc files in all projects for team consistency.
Back up global npm configurations before switching versions.
Use npm scripts to automate version switching across environments.
Advanced NVM Features
Custom Aliases:
nvm alias myproject 14.17.0
nvm use myproject
Running Commands with Specific Versions:
nvm exec 14.17.0 node script.js
Installing Global Packages Per Version:
nvm use 14.17.0
npm install -g yarn
Common Troubleshooting
PATH Conflicts: Check your shell profile configuration.
Permissions on macOS/Linux:
sudo chown -R $(whoami) ~/.nvm
Performance on Windows: Consider using the Windows Subsystem for Linux (WSL) for a Unix-like experience.
Conclusion
In 2025, efficiently using NVM to manage Node.js installations is more critical than ever. With the rapid evolution of the JavaScript ecosystem, the ability to easily switch between Node.js versions and manage multiple development environments is essential for modern developers. By mastering NVM and following the best practices outlined in this guide, you’ll be well-equipped to tackle the challenges of contemporary Node.js development, ensuring flexibility, consistency, and efficiency in your projects.
Originally published on https://codeinit.dev/blog/instalacao-e-gerenciamento-do-nodejs-com-nvm
Top comments (0)