Originally published on the Silicon Roundabout community blog
If you want to remove Node from your Unix machine: this is how you do it properly! Ok this is mostly for Linux, but I think you may find it useful if you are on a Mac too and get stuck with traces of Nodejs -aka: node.
It’s actually not that complex, or at least it should not be. But then sometimes we make those silly mistakes such as installing node once with apt-get and once with nvm. Or maybe it even came with the machine… Or at least this is what I’m trying to blame it to in my case. I know it was not the case, but hey…
There are plenty of Stack overflows and blog posts about this, so why another?
Well… it turns out that I had to piece together several sources to get to something that worked for me. And since it’s been a while since my last article, I thought: why not share how I actually got around to do a tabula-rasa of any node trace in my system?
But wait! Why would you want to do that?
Reasons can be many. In my case I had some issues with the installation of as node_module and, after travelling down several rabbit holes to fix it, I realised I had to give a go to uninstalling and then re-installing node completely, together with npm and any spare version of these laying around in my machine.
Because of this, I’m also going to share (bonus, yeah!!) how to re-install node and npm in a clever way: using an appropriate node package management tool: nvm.
If you have used nvm to install node (or at least “a” node), you’ll need to get rid of that:
- Find out which version of node you currently have: node -v
- Deactivate the current version of node: nvm deactivate
- nvm uninstall X.Y.Z (where the last bit is whatever version of node you have)
- Repeat for as long as you have live node versions managed by nvm
Here is where things got tricky for me. Because The node -v command would yield a version, but nvm uninstall could not help me get rid of it!
The answer was that I had node also installed directly withing the machine. If you are on the same boat, read on:
You might have installed it from source. Or you might have installed it with a package manager. Either way, you’ll have to get it out of your system by removing the installation AND making sure you don’t leave any dependencies behind.
On Linux (Debian, Ubuntu, Pop_OS, etc) you would have probably used apt-get. On Linux RHEL Flavours (Fedora, CentOS, Etc) probably dnf. On a Mac either Homebrew (brew) or Mac Ports (port).
If you’re on Linux, you remove installed packages and their dependencies with the following commands:
sudo apt-get purge nodejs sudo apt-get autoremove
sudo dnf remove nodejs sudo dnf remove npm sudo dnf remove node sudo dnf autoremove
To make sure you’ve fully removed node js, npm and node_modules from Debian-based Linux distros such as Ubuntu or CentOS, you need to remove containers also which are at different locations. 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
After doing all the checks, the above should finally remove all traces of Node from your Unix (Linux of MaxOS) system.
The Donald just yesterday, clearly referring to the above tutorial
This bit is taken straight out of the clearest guide for Linux and MacOS I know of:
- Download the nvm install script via cURL:
- curl -o- raw.githubusercontent.com/creationix/nvm/v0.. | bash
- Ensure that nvm was installed correctly with nvm --version, which should return the version of nvm installed (you might need to restart your terminal)
- Install the version of Node.js you want
- Install the latest version with nvm install node
- Use the latest version with nvm use node
- Install the latest LTS version with nvm install --lts
- Use the latest LTS verison with nvm use --lts
You now have a fresh installation of Nodejs, which of course comes with npmYou can test everything is running smoothly by checking them with:
node -v npm -v
These should return their respective version.
npm install --global yarn
which you can check with yarn -v…And that’s it everyone. If you get stuck with a messy node / npm / yarn setup on your machine, sometimes restarting with a clean slate is just the best option.
Here is how you completely and utterly remove Node from your Unix system, and then put it back using