How to remove nodejs from Ubuntu 16.04?

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

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.

  1. 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
    
  2. Remove node or node_modules directories from /usr/local/lib with the help of following command.

    sudo rm -rf /usr/local/lib/node*
    
  3. Remove node or node_modules directories from /usr/local/include with the help of following command.

    sudo rm -rf /usr/local/include/node*
    
  4. Remove any node file or dir from /usr/local/bin with the help of following command.

    sudo rm -rf /usr/local/bin/node*
    
  5. Go to home directory and remove any node or node_modules directory, if exists.


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.

Tags:

Apt

Uninstall