Can't uninstall global npm packages after installing nvm
Asked Answered
F

8

60

I've found several threads related to this issue but none seem to deal with my case specifically and I've been unable to solve using the suggestions I've found.

When I run npm uninstall -g "some package"

it just returns: up to date in .043s - And the global package remains.

For example I'm trying to uninstall babel-cli and after running npm uninstall -g babel-cli I'm still able to use the cli.

This started after I uninstalled node and npm and reinstalled using nvm. I'm wondering if I missed something while uninstalling node and it's causing the issue. I checked my dot files and noticed I still have a .npm outside of .nvm. Is that normal? Thanks in advance for any suggestions.

Finite answered 12/12, 2017 at 0:51 Comment(4)
This is possibly caused by having multiple paths in the your PATH environment variable and babel-cli installed for different versions of node. What is returned when you run which babel or which babel-cli (whatever the executable name is)?Dent
/usr/local/bin/babelFinite
Looks like it was installed globally. As far as I know nvm doesn't install executables there. Is it possible you also installed babel with another package manager like brew on macOS?Dent
I thought I was having this problem, but I was omitting the "@" in the package name. If you're in the same situation as me, remember the "@". e.g. npm uninstall -g @angular/cliVasty
M
88

(nvm maintainer here)

The list of things that you can npm uninstall -g is available at npm ls -g --depth=0. If you don't see the thing you want to uninstall there, but you can still access it, then if it was npm-installed, it was probably installed with your system version of node.

You can quickly verify this with nvm use system && npm ls -g --depth=0. If you see the package there, then while using the system version, you can npm uninstall -g it.

Mistiemistime answered 16/12, 2017 at 21:6 Comment(11)
I have no system npm installed (only nvm). I can see the package I want to uninstall via npm ls -g --depth=0, but still can't uninstall it. Additionally, npm ls -g --depth=0 outputs this: npm ERR! invalid: [email protected] /home/<...>/.nvm/versions/node/v8.9.4/lib/node_modules/npm/node_modules/tar/node_modules/minizlib after the packages listBasle
Aha - in this case, it seems like the copy of npm that the specific node install has (v8.9.4) is corrupt. The easiest solution, unfortunately, is to uninstall that node version and reinstall it - nvm deactivate && nvm uninstall 8.9.4 && nvm install 8.9.4 should do it.Mistiemistime
Looks like that was the case. Everything works after reinstalling.Basle
Glad to hear it!Mistiemistime
Holy mother of god. Why is this not written up in bold somewhere ? :D thanks a lotDaiquiri
Took 4 days to track this answer down. Thanks a lot!Heida
None of this works for me, nvm deactivate is not a command on my version. (1.0.1)Foothill
@DanielCooke that's because you're not using nvm, which hasn't yet hit v1.0. Perhaps you're using nvm-windows, a different project? (real nvm only works on Windows using WSL)Mistiemistime
I'm on macos, been ages since I installed it - not sure. I fixed it by removing the command from /usr/local/binFoothill
@Mistiemistime what does "nvm deactivate" does in the above recommendation? In other words would nvm uninstall not do the job? The reason I am asking is because after I did "nvm deactivate" I get "No .nvmrc file found" message; seems like nvm had been removed from $path variableLackaday
@esental nvm uninstall removes node, not nvm. deleting the nvm files doesn't unload it from your shell session - that's what nvm deactivate does.Mistiemistime
K
17

Sorry I know this is an old question but here we are in 2019 and was just an issue for me ... what I found is that I needed to invoke uninstall on the npm at the path that NVM cares about.

Here's what worked for me:

Tue Aug 20 08:09:07 ~
<username> $ npm uninstall -g [email protected]
up to date in 0.051s
Tue Aug 20 08:09:13 ~
<username> $ edgemicro --version
current nodejs version is v8.16.0
current edgemicro version is 3.0.4
3.0.4
// Clearly didn’t work :(

// Let’s try sudo ….
Tue Aug 20 08:09:18 ~
<username> $ sudo npm uninstall -g [email protected]
Password:
up to date in 0.035s
Tue Aug 20 08:10:20 ~
<username> $ edgemicro --version
current nodejs version is v8.16.0
current edgemicro version is 3.0.4
3.0.4
// Still didn’t work :(

// So where is this seemingly immortal executable?
Tue Aug 20 08:10:28 ~
<username> $ which edgemicro
/Users/<username>/.nvm/versions/node/v8.16.0/bin/edgemicro
// It’s under some NVM specific path it seems.
// It seems NPM is also under some NVM specific path, kinda expected.
Tue Aug 20 08:10:33 ~
<username> $ which npm
/Users/<username>/.nvm/versions/node/v8.16.0/bin/npm

// So let’s use that exact npm to perform the uninstall …
Tue Aug 20 08:10:42 ~
<username> $ /Users/<username>/.nvm/versions/node/v8.16.0/bin/npm uninstall -g edgemicro
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but npm-shrinkwrap.json was generated for lockfileVersion@0. I'll try to do my best with it!
removed 2442 packages in 25.851s
Tue Aug 20 08:11:24 ~
<username> $ which edgemicro
Tue Aug 20 08:11:29 ~
<username> $ // Done.
Kranz answered 20/8, 2019 at 15:26 Comment(3)
I had to also do this /usr/local/bin/npm uninstall -g create-react-appChevrotain
Worked for me. Don't know why we would need to get through all that...Ewe
Thanks! Though it did take an extra step for me, I opened Finder in the directory you found, to delete my package.Roxyroy
F
7

None of the above solutions worked for me.

My nvm version was 1.0.1 - weird.

So none of the suggested:

nvm deactivate && nvm uninstall..

Worked for me, as they are not commands.

I was trying to uninstall create-react-app

which create-react-app
/usr/local/bin/create-react-app

I just done the most obvious and naive thing

rm -rf /usr/local/bin/create-react-app

And its all good!

Foothill answered 13/1, 2020 at 11:49 Comment(2)
nvm deactivate && nvm uninstall web-push -g worked for me. Thanks @danielMohenjodaro
I gave up, and did the same: just removed the binary manually.Casares
S
4

I was trying to remove create-react-app to use the latest version of it using npx but kept getting the same warning even if I globally remove it.

You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0).

We no longer support global installation of Create React App.

Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app

So i thought that it might be about npm cache.

Go to:

C:\Users\{YOUR-LOCAL-USERNAME}\AppData\Local\npm-cache\_npx

You will find some folders which randomly named like c67e93de6234c87c. These folders contains latest packages you tried to use via npx.

So now, you should find the folder that contains the package you are trying to remove. You can find it by reading package.json in each of these folders.

When you find the correct directory, uninstall the package you are trying to remove within this directory using local uninstall command (not npm -g uninstall):

npm uninstall create-react-app

Now you are free to use the latest version of the package via npx.

Sanson answered 29/3, 2022 at 22:35 Comment(0)
L
0

I had experienced the same for one of the npm global package and below solution worked for me. Please use sudo before your command to solve this. like sudo npm uninstall -g "some package"

Without sudo: []$ npm uninstall -g truffle up to date in 0.082s

After trying with sudo: []$ sudo npm uninstall -g truffle [sudo] password for shahid: removed 81 packages in 1.902s

[]$:truffle bash: /usr/bin/truffle: No such file or directory

Local answered 25/12, 2018 at 7:11 Comment(0)
Z
0

I tried a few of the answers here, but nothing was working for me. I ended up deleting it myself like this: which <package_name> (alternatively you could use "which npm")

go to the where the executable is located in my case it was:

/c/Program Files/nodejs/<package_name>

go to the node_modules in there:

cd /c/Program Files/nodejs/node_modules

find your package name in there, and remove it like this:

rm -rf <package_name>

I also removed all references of the file in /c/Program Files/nodejs/ like in my case:

rm -rf /c/Program Files/nodejs/<package_name> (the executable)

rm -rf /c/Program Files/nodejs/<package_name>.ps1

rm -rf /c/Program Files/nodejs/<package_name>.cmd

Zealous answered 19/4, 2023 at 17:52 Comment(0)
T
-1

No matter how many times you call npm uninstall babel,

OR Yarn uninstall -g babel

OR Yarn uninstall -g babel-cli

It does shows updated. And when you check it if it still exists by entering "babel -help"

You get this- > babel still somewhere in your Mac

I know its frustrating. So I found where these files get stored locally and after removing them from local storage, I finally got -> Finally my system doesn't understand what babel is. What we really want

How did I find it:

Finder's search result is not going to give you path of the global babel storage. I found that there is a folder called /usr in in our real-root directory "Macintosh HD" It is hidden

So, Select finder -> Go -> Go to Folder.. And type "/usr".

A new finder window will open and it will show all the files inside it. Now you can roam around and check all the files you installed, some probably forgotten and never got a chance to remove.

Go to usr/local/bin -> and here you will find the files which you globally installed. as shown here - > Directory of shortcuts

Again, as you can see, there are arrow signs on the icons, which indicate that these are just the shortcuts. Deleting them will cut the link, but the files will still be there somewhere.

To delete the files, right click on the icon and select "Show Original"

You will be redirected to a folder where you will find babel.js file.

Remember, its again just one file. To completely remove the babel-cli, select the column view in the finder, and you can scroll left and check its parent directories. And here is where the actual installations are done.

finalpath part 1

finalpath part 2

You can see, just like basic node modules that gets installed in our local web projects, babel-cli and similar such packages gets installed in similar format but in these global location.

Now you can right-click the babel-cli folder and move it to trash.

Hope the hunt is finally over.

Transcendence answered 20/4, 2018 at 15:8 Comment(0)
C
-2

I know this is an old question but if none of the options above work, do this. Go into terminal or command prompt and type "open /usr/local/bin". It will open the hidden folder of 'usr' and look for the file you want to delete. Hopefully this helped.

Cadent answered 19/3, 2020 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.