To run this, you can try:
curl -ksO https://gist.githubusercontent.com/chriswayg/cd923e933062f0c053a417fa6bf1094e/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh
| #!/bin/sh | |
| (( ${#} > 0 )) || { | |
| echo 'DISCLAIMER: USE THIS SCRIPT AT YOUR OWN RISK!' | |
| echo 'THE AUTHOR TAKES NO RESPONSIBILITY FOR THE RESULTS OF THIS SCRIPT.' | |
| echo "Disclaimer aside, this worked for the author, for what that's worth." | |
| echo 'Press Control-C to quit now.' | |
| read | |
| echo 'Re-running the script with sudo.' | |
| echo 'You may be prompted for a password.' | |
| sudo ${0} sudo | |
| exit $? | |
| } | |
| # This will need to be executed as an Admin (maybe just use sudo). | |
| # [CHW]: added some lines to remove more files (some deletions are redundant) | |
| for bom in org.nodejs.node.pkg.bom org.nodejs.pkg.bom; do | |
| receipt=/var/db/receipts/${bom} | |
| [ -e ${receipt} ] && { | |
| # Loop through all the files in the bom. | |
| lsbom -f -l -s -pf ${receipt} \ | |
| | while read i; do | |
| # Remove each file listed in the bom. | |
| # Changed based on comments under original Gist. | |
| rm -v /usr/local/${i#./usr/local/} | |
| done | |
| } | |
| done | |
| npm uninstall npm -g | |
| # Remove directories & files related to node.js. | |
| rm -rfv /usr/local/lib/node | |
| rm -rfv /usr/local/lib/node_modules | |
| rm -rfv /var/db/receipts/org.nodejs.* | |
| rm -rfv /usr/local/include/node | |
| rm -rfv /usr/local/share/doc/node | |
| rm -v /usr/local/share/man/man1/node* | |
| rm -v /usr/local/share/man/man1/npm* | |
| rm -v /usr/local/lib/dtrace/node.d | |
| rm -v /usr/local/share/systemtap/tapset/node.stp | |
| rm -v /usr/local/bin/node | |
| rm -v /usr/local/bin/npm | |
| rm -v /usr/local/bin/npx | |
| rm -v $HOME/.npmrc | |
| rm -rfv $HOME/.npm | |
| exit 0 |