npm uninstall -g does nothing, or global packages vanished after installing nvm
npm uninstall -g <package> finishes but the command is still thereShort answer
nvm gives every Node version its own global packages, and npm only sees the active one. Packages installed before nvm live with the system Node. Switch to the version that holds the package, then run npm uninstall -g. A stray prefix setting can also point npm at the wrong folder.
Fix it fast
1Find out which cause you have
Ask npm which Node is active and which global folder it is reading, then compare with where the program really lives.
nvm current npm prefix -g command -v <package-command>2Match what you see, then jump to its fix
- 1
command -v shows a path outside ~/.nvm, such as /usr/local/binThe package belongs to the system Node, not the nvm oneFix - 2
npm ls -g misses the package, and command -v finds it under ~/.nvm/versions/node/<other version>The package was installed under another nvm Node versionFix - 3
npm prefix -g points outside the active nvm version's folderA prefix setting redirects npm to another folderFix
- 1
What does the error look like?
npm uninstall -g <package> finishes but the command is still therenpm ls -g does not list a package you installed globally before nvm
Cause 1 of 3
The package belongs to the system Node, not the nvm one
1Check
Packages installed before nvm sit in the global folder of the system Node. nvm swaps in its own Node, and npm then looks only in that Node's folder.
nvm ls
command -v <package-command>2Fix
Switch to the system Node with the special alias, uninstall there, then switch back.
nvm use system
npm uninstall -g <package>
nvm use 223Verify
The command is gone from the shell.
command -v <package-command>Confirmed by github.com
Cause 2 of 3
The package was installed under another nvm Node version
1Check
The global packages of each nvm version live in that version's own folder, so uninstalling from version B does not touch version A.
nvm ls
nvm which 202Fix
Use the version that holds the package, uninstall, and return to your working version.
nvm use 20
npm uninstall -g <package>
nvm use 223Verify
List the global packages for the version you removed it from.
npm ls -g --depth=0Confirmed by github.com
Cause 3 of 3
A prefix setting redirects npm to another folder
1Check
nvm does not work with a prefix set in ~/.npmrc, or with the NPM_CONFIG_PREFIX or PREFIX environment variables. npm then installs and removes global packages in that folder instead of the nvm one.
grep prefix ~/.npmrc
echo "$NPM_CONFIG_PREFIX" "$PREFIX"2Fix
Remove the prefix line from ~/.npmrc by editing the file, and unset the variables, then open a new terminal and check the prefix again.
unset NPM_CONFIG_PREFIX PREFIX3Verify
npm prefix -g now sits inside the active nvm version.
npm prefix -gConfirmed by github.com
How do I stop it coming back?
- Keep your list of global tools short and use npx or project devDependencies for the rest.
- After installing a new Node version, copy globals with nvm reinstall-packages instead of installing them again by hand.
- Do not set a global prefix in ~/.npmrc on a machine that uses nvm.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
node and npm vanish or are not found when nvm is installed
nvm current prints system in a new shell
nvm adds node and npm to PATH only for the version it has activated.
4 causes, each with a fixBack end
Node installed with nvm is missing when you use sudo or log in as root
nvm: command not found
nvm is a shell function loaded from your own profile and its files sit in your own home folder.
3 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
corepack enable fails: permission denied while creating the pnpm link
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm'
corepack enable writes small link files for yarn and pnpm next to your node binary.
2 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fix