Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm uninstall -g does nothing, or global packages vanished after installing nvm

Errornpm uninstall -g <package> finishes but the command is still there

Short 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.

  • Applies to npm 10, Node.js 22, macOS, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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>
  2. 2Match what you see, then jump to its fix

    1. 1command -v shows a path outside ~/.nvm, such as /usr/local/binThe package belongs to the system Node, not the nvm oneFix
    2. 2npm 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. 3npm prefix -g points outside the active nvm version's folderA prefix setting redirects npm to another folderFix

What does the error look like?

  • npm uninstall -g <package> finishes but the command is still there
  • npm 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 22

3Verify

The command is gone from the shell.

command -v <package-command>

Confirmed by github.com

Did this fix it?

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 20

2Fix

Use the version that holds the package, uninstall, and return to your working version.

nvm use 20
npm uninstall -g <package>
nvm use 22

3Verify

List the global packages for the version you removed it from.

npm ls -g --depth=0

Confirmed by github.com

Did this fix it?

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 PREFIX

3Verify

npm prefix -g now sits inside the active nvm version.

npm prefix -g

Confirmed by github.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.