How to remove nodejs from Ubuntu 16.04?
Solution 1
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 essentially 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
Solution 2
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 have posted the procedure to remove NodeJS on my blog: AMCOS IT Support For Windows and Linux: To completely uninstall node js from Ubuntu.
First of all you need to run the following command from command terminal as sudo.
sudo rm -rf /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
Remove node or node_modules directories from /usr/local/lib with the help of following command.
sudo rm -rf /usr/local/lib/node*
Remove node or node_modules directories from /usr/local/include with the help of following command.
sudo rm -rf /usr/local/include/node*
Remove any node file or dir from /usr/local/bin with the help of following command.
sudo rm -rf /usr/local/bin/node*
Go to home directory and remove any node or node_modules directory, if exists.
Solution 3
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.
Solution 4
To manually remove nodejs
, npm
and node_modules
from Ubuntu, you need to do the following steps:
Run the following command from the terminal as
sudo
:sudo rm -rf /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
Remove
node
ornode_modules
directories from/usr/local/lib
with the help of the following command:sudo rm -rf /usr/local/lib/node*
Remove
node
ornode_modules
directories from/usr/local/include
with the help of the following command:sudo rm -rf /usr/local/include/node*
Remove any
node
file or directory from/usr/local/bin
with the help of the following command:sudo rm -rf /usr/local/bin/node*
Go to your home directory and remove any
node
ornode_modules
directory, if exists.
Now it is done.
Solution 5
I had this challenge when working on an Ubuntu 20.04 machine with Nodejs.
For me, I had to run the following commands to remove nodejs and all of it's dependencies.
This is to remove nodejs and it's dependencies:
sudo apt-get purge nodejs
This is to remove any dependencies that are still left after removing nodejs
sudo apt-get autoremove
This is to remove the nodejs repository from the /etc/apt/sources.list.d
directory:
sudo rm -rf /etc/apt/sources.list.d/nodesource.list*
Update your package repository list:
sudo apt-get update
Confirm if the node executable is still available in your machine:
which node
That's all.
I hope this helps
Related videos on Youtube
user1063287
Here are some answers I hope will be helpful to others: JavaScript If primitives are immutable and have no methods, why can a method be called on a string? Security How to secure a comment form in a non-CMS environment with no user authentication? Node How to use Helmet to define Content Security Policy? How do routes, middleware and next work in Express? How to split a string into chunks of a particular byte size? OpenShift How to view OpenShift Online node application logs locally? How to connect to OpenShift 3 MongoDB remotely? Miscellaneous (Git Bash) How to create a multi-terminal Git Bash environment with Windows Terminal? (Codepen) How to add a syntax highlighting theme to codepen? And here are some links to recommended learning content: JavaScript: Understanding the Weird Parts - The First 3.5 Hours (YouTube video link) This is a great, and deep, introduction to JavaScript that will answer a lot of questions new JS developers will have about common terminology and dynamics. I wish I had viewed it when I first started.
Updated on September 18, 2022Comments
-
user1063287 almost 2 years
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
andnpm
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
andnpm
?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]
-
edwinksl about 8 yearsHow about trying stackoverflow.com/a/33947181/486919?
-
user1063287 about 8 years@heemayl - have added output to post, and just went ahead with that approach.
-
-
Nikhil VJ almost 5 yearsThis 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. -
Garrett about 4 yearsThis worked. The accepted answer (
sudo apt-get purge --auto-remove nodejs
) still left/usr/local/bin/node
on my ubuntu 18.04 machine. -
Färid Alijani almost 4 yearswhich command should I use to remove nodes in
/etc/apt/sources.list.d
? what should I remove? I havenodesource.list
! so probablysudo rm -rf /etc/apt/sources.list.d/nodesources.list*
? -
Promise Preston over 3 yearsYes, run
sudo rm -rf /etc/apt/sources.list.d/nodesources.list*
to remove nodejs source from/etc/apt/sources.list.d
directory.