What's the best way to remove Node.js, NPM, and all related packages from Ubuntu?

Hey everyone! I’m trying to do a clean sweep of Node.js and NPM from my Ubuntu machine. I originally installed Node.js using sudo apt-get install node, but now I want to get rid of everything.

I’m talking about:

  • Node.js itself
  • NPM
  • All the global packages I’ve installed (like @vue/cli)
  • Any other files or libraries that came along for the ride

Does anyone know the most thorough way to do this? I’m planning to reinstall everything fresh afterward, but first I want to make sure I’ve wiped the slate clean.

Here’s a quick example of what I’ve tried, but I’m not sure if it’s enough:

sudo apt-get remove nodejs
sudo apt-get purge npm
rm -rf ~/.npm
rm -rf ~/.node-gyp

Is there anything else I should be doing? Thanks in advance for any help!

yo, i feel ya. been there, done that. heres wat i do:

sudo apt-get purge nodejs npm
sudo apt-get autoremove
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/node*

then check ur home dir for any sneaky .npm or .nvm folders n nuke em. shud be squeaky clean after that

I’ve been down this road before, and let me tell you, it can be a bit tricky to get everything cleaned up. Here’s what worked for me:

First, I’d recommend using the Node Version Manager (NVM) to uninstall Node.js. It’s much cleaner than just removing packages. If you don’t have NVM, you can install it and then use it to remove Node.

Then, I’d go through and remove any global packages manually. You can list them with npm list -g --depth=0 and remove each one.

After that, I’d clean up any leftover directories:

rm -rf ~/.nvm
rm -rf ~/.npm
rm -rf ~/.node-gyp
rm -rf ~/.node_repl_history

Finally, check for any remaining Node-related binaries in /usr/local/bin and remove them.

This approach has always given me a clean slate to work with. Just be careful not to remove anything you might need for other projects!