如何从Ubuntu 16.04删除Node.js?


42

复制步骤:

Ubuntu 16.04 Xenial(x86-64)

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

我想卸载nodejsnpm并且看到了几则帖子,提示这是最常见的方式:

sudo apt-get purge --auto-remove nodejs

但是,这会产生一个提示,该提示似乎引用了依赖项,如果删除了这些依赖项,听起来好像会引起问题。

什么是“撤销”的最佳方式安装的nodejsnpm

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  gyp* libboost-python1.58.0* libjs-inherits* libjs-node-uuid*
  libjs-underscore* libssl-dev* libssl-doc* libuv1* libuv1-dev*
  linux-headers-4.4.0-18* linux-headers-4.4.0-18-generic*
  linux-headers-4.4.0-21* linux-headers-4.4.0-21-generic*
  linux-image-4.4.0-18-generic* linux-image-4.4.0-21-generic*
  linux-image-extra-4.4.0-18-generic* linux-image-extra-4.4.0-21-generic*
  linux-signed-image-4.4.0-18-generic* linux-signed-image-4.4.0-21-generic*
  node-abbrev* node-ansi* node-ansi-color-table* node-archy* node-async*
  node-block-stream* node-combined-stream* node-cookie-jar*
  node-delayed-stream* node-forever-agent* node-form-data* node-fstream*
  node-fstream-ignore* node-github-url-from-git* node-glob* node-graceful-fs*
  node-gyp* node-inherits* node-ini* node-json-stringify-safe* node-lockfile*
  node-lru-cache* node-mime* node-minimatch* node-mkdirp* node-mute-stream*
  node-node-uuid* node-nopt* node-normalize-package-data* node-npmlog*
  node-once* node-osenv* node-qs* node-read* node-read-package-json*
  node-request* node-retry* node-rimraf* node-semver* node-sha* node-sigmund*
  node-slide* node-tar* node-tunnel-agent* node-underscore* node-which*
  nodejs* nodejs-dev* npm* python-configobj* python-pycurl* python-pyexiv2*
  python-pyexiv2-doc*
0 to upgrade, 0 to newly install, 72 to remove and 0 not to upgrade.
After this operation, 631 MB disk space will be freed.
Do you want to continue? [Y/n]

编辑:

这是来自的输出sudo apt-get purge nodejs

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gyp libboost-python1.58.0 libjs-inherits libjs-node-uuid libjs-underscore
  libssl-dev libssl-doc libuv1 libuv1-dev linux-headers-4.4.0-18
  linux-headers-4.4.0-18-generic linux-headers-4.4.0-21
  linux-headers-4.4.0-21-generic linux-image-4.4.0-18-generic
  linux-image-4.4.0-21-generic linux-image-extra-4.4.0-18-generic
  linux-image-extra-4.4.0-21-generic linux-signed-image-4.4.0-18-generic
  linux-signed-image-4.4.0-21-generic python-configobj python-pycurl
  python-pyexiv2 python-pyexiv2-doc
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  node-abbrev* node-ansi* node-ansi-color-table* node-archy* node-async*
  node-block-stream* node-combined-stream* node-cookie-jar*
  node-delayed-stream* node-forever-agent* node-form-data* node-fstream*
  node-fstream-ignore* node-github-url-from-git* node-glob* node-graceful-fs*
  node-gyp* node-inherits* node-ini* node-json-stringify-safe* node-lockfile*
  node-lru-cache* node-mime* node-minimatch* node-mkdirp* node-mute-stream*
  node-node-uuid* node-nopt* node-normalize-package-data* node-npmlog*
  node-once* node-osenv* node-qs* node-read* node-read-package-json*
  node-request* node-retry* node-rimraf* node-semver* node-sha* node-sigmund*
  node-slide* node-tar* node-tunnel-agent* node-underscore* node-which*
  nodejs* nodejs-dev* npm*
0 to upgrade, 0 to newly install, 49 to remove and 0 not to upgrade.
After this operation, 27.6 MB disk space will be freed.
Do you want to continue? [Y/n]

1
可能来自的许多无关软件包autoremove。当您跑步时会发生什么sudo apt-get purge nodejs
heemayl


@heemayl-在发布后增加了输出,并继续使用该方法。
user1063287

Answers:


62

从以下输出中可以看出:

sudo apt-get purge nodejs

它只是删除node相关的软件包,即相关的软件包,仅此而已。

另一方面,当您这样做时:

sudo apt-get purge --auto-remove nodejs

它一定在做:

sudo apt-get purge nodejs
sudo apt-get autoremove

和去除的gyplinux-headers-4.4.0-18-generic等包实际上是由触发的autoremove,因为他们是一个安装的依赖,不再受任何已安装的程序包所需,大概是因为主包已被删除。

因此,在这种情况下运行是完全可以的:

sudo apt-get purge --auto-remove nodejs

如果您过于偏执,可以分两个步骤进行:首先purge nodejs

sudo apt-get purge nodejs

然后删除孤立的依赖项(直到现在,如果有的话):

sudo apt-get autoremove

8

要从Ubuntu中删除node js,npm和node_modules,您还需要删除在Ubuntu中不同位置的容器。这些可能是:

/usr/local/bin/npm/usr/local/share/man/man1/node/usr/local/lib/dtrace/node.d~/.npm ~/.node-gyp/opt/local/bin/nodeopt/local/include/node/opt/local/lib/node_modules

我成功做到了。所以我要分享整个程序

您需要按照http://amcositsupport.blogspot.in/2016/07/to-completely-uninstall-node-js-from.html中的步骤进行操作


2
欢迎来到Ask Ubuntu!虽然从理论上讲这可以回答问题,但最好在此处包括答案的基本部分,并提供链接以供参考。
安华

这很有用-即使在purge命令执行后,甚至在重新启动后,仍然仍然保​​留了这些仍像节点/ npm一样运行的二进制文件。仅在删除二进制文件之后,才可以完全卸载。
Nikhil VJ

4

sudo apt-get remove nodejs

sudo apt-get remove npm

然后转到/etc/apt/sources.list.d并删除所有节点列表(如果有)。然后做一个

sudo apt-get update

检查主文件夹中是否有任何.npm或.node文件夹,并将其删除。

如果您输入

which node

您可以看到节点的位置。尝试which nodejswhich npm太。

我建议使用节点版本管理器(NVM)安装节点。那为我节省了很多头痛。因为您可以使用nvm安装nodejs和npm而不使用sudo。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.