How to uninstall n and all node versions installed by n

て烟熏妆下的殇ゞ 提交于 2019-12-12 08:27:39

问题


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?


回答1:


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:

  • Cant uninstall n and node #327
  • Simple command to switch back to the system installation of Node #486



回答2:


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 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!)




回答3:


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.



来源:https://stackoverflow.com/questions/49648514/how-to-uninstall-n-and-all-node-versions-installed-by-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!