Uninstall and re-Install Node.js

Have you ever had to remove and reinstall Node.js? It happens a lot to us developers! For those of you who don’t decide to reset your machine all the way back to CMOS bios, here’s a best practice to help you get going again and be ready to develop new projects!

Step1: Uninstall Node.js

$ sudo apt remove nodejs

$ sudo apt purge nodejs (to remove configs)

$ sudo apt autoremove (to remove dependencies)

Step 1.1: Double-check with:

$ node -v

Step 2: Deep clean your machine

$ sudo rm -rf /usr/local/bin/npm

$ sudo rm -rf /usr/local/share/man/manl/node*

$ sudo rm -rf /usr/local/lib/dtrace/node.d

$ sudo rm -rf ~/.npm

$ sudo rm -rf ~/.node-gyp

$ sudo rm -rf /opt/local/bin/node

$ sudo rm -rf /opt/local/include/node

$ sudo rm -rf /opt/local/lib/node_modules

$ sudo rm -rf /usr/local/lib/node*

$ sudo rm -rf usr/local/include/node*

$ sudo rm -rf usr/bin/node*

Now, last step go to /home directory and check and remove manually any node or node_modules directory

Step 2.1: Double check uninstalling node

$ which node

$ which nodeis

Now let’s install Node.js

Step.3: Install Node.js on Ubuntu

$ cd ~

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get install curl

We install node.js via pm (package manager) for Debian and Ubuntu based Linux distributions. Choose the official version of your Node.js here: nodesouces/distributions

For instance let’s install v.16.x LTS

# Using Ubuntu

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

sudo apt-get install -y nodejs

Just a little refresh and your Ubuntu is ready to code!

$ sudo apt-get update && sudo apt-get upgrade

Check your version

node -v

Thanks for reading.

A.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store