How to uninstall n and all node versions installed by n
Asked Answered
D

4

40

I have installed some Node.js versions with the tool n. I have uninstalled all Node.js versions using:

sudo n prune

except the current (activated) version. If I try to unsinstall the current version:

sudo n rm 6.10.2

I get the following error.:

Error: cannot remove currently active version (node/6.10.2).

I can not figure out, how to set the systems (Arch Linux) default Node.js version, which is already installed and was used to install n.

If uninstall n using:

sudo npm uninstall -g n

it leaves the current version on my computer.

ls /usr/local/n/versions/node/                                                                                                                                                                      
6.10.2/

Do I need to manually delete the folder: /usr/local/n/? Or, is there an option in n to uninstall it and all the Node.js versions installed by n, so that I get the setting before I installed n?

Desiderate answered 4/4, 2018 at 10:16 Comment(0)
D
51

You need to manually remove Node versions installed by n and set the correct Node system version.

sudo n prune
sudo npm uninstall -g n
sudo rm -r /usr/local/n
sudo rm /usr/local/bin/node 

See the following issues for n on GitHub:

Desiderate answered 5/4, 2018 at 8:17 Comment(2)
See also How to uninstall n? #169Theatricals
This needs to add some context about how to switch back to the system PATH for node, if it's available. This leaves you with no way to npm i -g n if you wanted to reinstall n.Iy
E
3

There have been some changes in n, so I'll provide an updated and longer answer.

First some context. n installs by default to /usr/local. If that is also the location of the "system" install of node and npm then it is overwritten. The cache of previously downloaded versions is kept in /usr/local/n.

Removing cached node versions downloaded by n:

  • n prune removes all but the version matching the active version of node
  • since n v3.0.0, deleting the active version is allowed using n rm <version>
  • (but just manually deleting /usr/local/n is easy and removes the top folder too!)

Removing installed node and npm and npx et al:

  • since n v4.1.0, there is n uninstall. (You will need to reinstall the system node and npm to keep using them if they were installed to same location and overwritten.)

Uninstalling n itself: if you installed it with npm install n then you uninstall it with npm uninstall n. This does not affect the cached versions of node or the installed version of node, just n. (And there is a small catch-22 if just deleted npm by running n uninstall!)

Erickson answered 17/5, 2019 at 1:3 Comment(0)
A
-1

I'm on mac OSX, so I'm not sure if this is relevant to your use case or not, but it may help.

It looks like n may run into issues if you remove the current version, so I suggest that you delete the folder: /usr/local/n/

Then try to uninstall 'n'. In my case, running npm uninstall -g n did not remove n. Instead, I needed to find the current installation of n by running: which n, then removing that folder from my system.

Then, I would suggest that you use NVM instead. I've found that it's the easiest and most reliable solution that I've found to date.

More specifically, to address your question about how to access the system installation of node, I don't know what OS you are running, but I don't know that there is a system node version.

Typically, you have to manually install node. If there were a system node version, I would expect that it would become outdated very quickly, considering node, and other tools, typically iterate through changes fairly quickly.

I hope this works for you.

Anders answered 4/4, 2018 at 15:10 Comment(1)
"It looks like n may run into issues if you remove the current version...". What do you mean? I didn't have removed the current version. In my case npm uninstall -g n removed n successfully. My question is tagged with archlinux, so I use Linux as OS. Archlinux is a rolling release distribution, so I get the newest Node.js, but that's not the question. I just want to remove the current node version from n, so that I can afterwards remove n.Desiderate
B
-1

Run n-uninstall to uninstall n as well as the Node.js versions that were installed with it. n-uninstall -y skips the confirmation prompt - use with caution.

Bituminous answered 28/1, 2020 at 7:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.