42

Steps to replicate:

Ubuntu 16.04 xenial (x86-64)

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

I want to uninstall nodejs and npm and have seen several posts which suggest this is the most common way:

sudo apt-get purge --auto-remove nodejs

However, this produces a prompt which seems to reference dependencies which, if they were removed, sound like they would cause problems.

What is the best way to "undo" the install of nodejs and npm?

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]

Edit:

This is the output from 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
    Possibly many extraneous packages from autoremove. What happens when you just run sudo apt-get purge nodejs? – heemayl Jun 12 '16 at 9:43
  • How about trying stackoverflow.com/a/33947181/486919? – edwinksl Jun 12 '16 at 9:43
  • @heemayl - have added output to post, and just went ahead with that approach. – user1063287 Jun 12 '16 at 9:56
61

As seen from the output of:

sudo apt-get purge nodejs

it is only removing node related packages i.e. relevant packages, nothing more.

On the other hand, when you do:

sudo apt-get purge --auto-remove nodejs

it is necessarily doing:

sudo apt-get purge nodejs
sudo apt-get autoremove

and the removal of the gyp, linux-headers-4.4.0-18-generic etc packages are actually triggered by autoremove as they were installed as dependencies and no longer needed by any installed package, presumably because the main package has been removed.

So it is perfectly fine in this context to run:

sudo apt-get purge --auto-remove nodejs

If you are too paranoid, you can do it in two steps: first purge nodejs:

sudo apt-get purge nodejs

and then remove the orphan dependencies (till now, if any):

sudo apt-get autoremove
8

To remove node js, npm and node_modules from Ubuntu, you need to remove containers also which are at different locations in Ubuntu. These could be as:

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

I did it successfully. So I am sharing the full procedure

You need to follow the steps as in http://amcositsupport.blogspot.in/2016/07/to-completely-uninstall-node-js-from.html

  • 2
    Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Anwar Nov 4 '16 at 14:43
  • This was helpful - even after the purge commands, even after restarting, these binaries where still left over and acting like node/npm was still installed and all. Only after removing the binaries is a full uninstall complete. – Nikhil VJ Sep 16 at 9:55
4

sudo apt-get remove nodejs

sudo apt-get remove npm

Then go to /etc/apt/sources.list.d and remove any node list if you have. Then do a

sudo apt-get update

Check for any .npm or .node folder in your home folder and delete those.

If you type

which node

you can see the location of the node. Try which nodejs and which npm too.

I would recommend installing node using Node Version Manager(NVM). That saved a lot of head ache for me. Because you can install nodejs and npm without sudo using nvm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.