How to completely uninstall node.js on a Mac

Author : houxue   2023-04-18 10:53:19 Browse: 792
Category : Python

Abstract: Preface: Many times, we install software on Mac just to save time. We download. dmg files or.pkg files directly and install them....

Preface:

Many times, we install software on Mac just to save time. We download. dmg files or.pkg files directly and install them. The configuration and environment variables are all automatically configured, but after installing like node.js, there is no entry point for complete uninstallation. Additionally, sometimes we need multiple environments with different node versions, which makes the above method a bit inconvenient, so it is still recommended to install binary packages and manually configure environment variables.

How to fully uninstall node.js?

Installation method of brew

Directly through a command

brew uninstall nodejs

Download the pkg installation package from the official website

Through this command

sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

In the form of scripts

Write a script, such as uninstallNodejs.sh

Add the following content:

#!/bin/bash
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom \
| while read i; do
  sudo rm /usr/local/${i}
done
sudo rm -rf /usr/local/lib/node \
     /usr/local/lib/node_modules \
     /var/db/receipts/org.nodejs.*

Authorize files

chmod 777 uninstallNodejs.sh

Finally, run the file file

Delete and clear other legacy files through a single instruction

sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules

Done!

Label :
    Sign in for comments!
Comment list (0)

Powered by TorCMS (https://github.com/bukun/TorCMS).