# Using Node Version Manager (NVM) for Linux/macOS
Switching npm versions is typically done by switching Node.js versions, as npm is bundled with Node.js. The recommended method for managing multiple Node.js (and thus npm) versions is through a Node Version Manager (NVM).
Using Node Version Manager (NVM) for Linux/macOS:
Install NVM.
Code
``` curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash ```
(Note: The version in the URL might need to be updated to the latest stable NVM version.) Verify NVM Installation.
Code
``` command -v nvm ```
- **Install a specific Node.js version (which includes its bundled npm):**
Code
``` nvm install ```
For example, to install Node.js version 18.12.1:
Code
``` nvm install 18.12.1 ```
List installed Node.js versions.
Code
``` nvm ls ```
- **Switch to a specific Node.js version:**
Code
``` nvm use ```
For example, to switch to Node.js version 18.12.1:
Code
``` nvm use 18.12.1 ```
Using NVM for Windows:
- **Uninstall existing Node.js:** Before installing NVM for Windows, uninstall any current Node.js installations. - **Download and install NVM for Windows:** Download the installer from the official NVM for Windows GitHub repository. - **Install a specific Node.js version:**
Code
``` nvm install ```
- **Switch to a specific Node.js version:**
Code
``` nvm use ```
Updating npm separately (less common):
If you need a specific npm version that is different from the one bundled with your current Node.js version, you can install it globally:
Code
``` npm install -g npm@ ```
For example, to install npm version 9.8.1:
Code
``` npm install -g npm@9.8.1 ```
However, using NVM to manage Node.js versions is generally the preferred approach as it ensures compatibility between Node.js and its bundled npm