Nvm vs npm: Key Differences Explained
In this article
Nvm (Node Version Manager) and npm (Node Package Manager) are two different tools that work together in the Node.js ecosystem: nvm manages which version of Node.js is installed on your system, while npm manages the JavaScript packages (libraries and tools) that your projects depend on. In short, nvm is for switching Node versions, npm is for installing and managing packages within a project.
Background: What Each Tool Does
Node.js is a JavaScript runtime that lets you run JavaScript outside a browser. It ships with a built-in package manager called npm, which downloads and manages third-party code libraries. Nvm is a separate, community-maintained tool that lets you install and switch between multiple versions of Node.js on the same machine. You might need nvm if you work on projects that require different Node versions, or if you want to test your code against the latest release without affecting your system-wide installation.
How npm Works
When you run npm install , npm fetches the package from the public npm registry (the largest software registry in the world) and places it in a node_modules folder in your project. It also records the exact version in a package.json file. Key npm commands include:
npm init– creates a newpackage.jsonnpm install– installs all dependencies listed inpackage.jsonnpm run– runs a custom script defined inpackage.jsonnpm update– updates packages to newer versions within the range specified
npm is included with Node.js, so when you install Node from the official website, you get npm automatically.
How nvm Works
Nvm is a shell script that modifies your environment variables to point to a specific Node.js installation. It does not replace npm; instead, it changes which Node version is active, and that Node version brings its own npm. Typical nvm commands:
nvm install 20– installs the latest Node.js 20.x releasenvm use 18– switches the active Node version to 18.xnvm ls– lists all installed Node versionsnvm alias default 20– sets the default Node version for new shells
When you switch Node versions with nvm, the npm version also switches because each Node installation includes its own npm. This is why you might see different npm versions after running nvm use.
Key Differences at a Glance
The table below summarizes the main contrasts:
- Purpose: nvm manages Node.js versions; npm manages JavaScript packages.
- Scope: nvm operates globally (system-wide); npm operates per project (local) or globally (with
-gflag). - Installation: nvm is installed separately; npm comes bundled with Node.js.
- Commands: nvm uses
nvm install/use; npm usesnpm install/run. - Dependency: nvm is not required for npm to work; npm works with any Node version.
When to Use Which
You need nvm when you have multiple projects that require different Node versions. For example, an older project might need Node 14, while a new project uses Node 20. Without nvm, you would have to uninstall and reinstall Node each time. Nvm solves this by letting you switch instantly.
You need npm for virtually every Node.js project because it is the standard way to install libraries like Express, React, or Lodash. Even if you never use nvm, you will use npm constantly.
A common workflow is: use nvm to choose a Node version, then use npm to install packages within that environment. They are complementary, not competing.
Common Misconception: “npm install -g” and nvm
Many developers think that globally installed npm packages (e.g., npm install -g create-react-app) are available across all Node versions. That is not true. Nvm isolates each Node version, so a global package installed under Node 18 is not available when you switch to Node 20. You must reinstall global packages for each Node version, or use nvm’s nvm reinstall-packages command to copy them.
How to Choose
If you are just starting with Node.js and only need one version, you do not need nvm – just install Node from the official site. If you work on multiple projects or contribute to open source, nvm is highly recommended. For npm, there is no alternative for most projects; it is the default package manager and is required for almost all Node workflows.
Frequently Asked Questions
Do I need nvm if I only use one Node version?
No. If you never switch versions, a single system-wide Node installation is sufficient. Nvm adds convenience only when you need multiple versions.
Can I use npm without nvm?
Yes. Npm comes with Node.js, so any Node installation includes npm. Nvm is optional and only affects which Node version is active.
Does nvm work on Windows?
The original nvm is for Unix-like systems (macOS, Linux). On Windows, use nvm-windows (a separate port) or the built-in nvm command in Windows Terminal if you use a package manager like Chocolatey. The commands are similar but not identical.
How do I update npm?
You can update npm to the latest version with npm install -g npm@latest. This updates npm within the currently active Node version. If you use nvm, you may need to do this for each Node version.
What is the difference between npx and npm?
Npx is a tool that comes with npm. It lets you run a package without installing it globally. For example, npx create-react-app my-app runs the package once without leaving it on your system. Npm is for installing and managing packages, while npx is for executing them.
Can I have both nvm and a system Node installed?
Yes, but they can conflict. Nvm typically takes over the node command in your shell, so the system Node may be shadowed. It is cleaner to uninstall the system Node and rely solely on nvm.