Skip to content

Instantly share code, notes, and snippets.

@bojoer
Forked from nicerobot/README.md
Last active January 4, 2016 11:09
Show Gist options
  • Save bojoer/8613437 to your computer and use it in GitHub Desktop.
Save bojoer/8613437 to your computer and use it in GitHub Desktop.

To run this, you can try:

curl -ks https://gist.github.com/bojoer/8613437/raw/uninstall-node.sh | bash

Alternatively,

curl -ksO https://gist.github.com/bojoer/8613437/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh

I've tested both methods and can confirm that both ways work except the first method will not run if you did not allow executing of unverified author or untrusted applications and scripts.

#!/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).
# Verify the bom exists, otherwise don't do anything
[ -e /var/db/receipts/org.nodejs.pkg.bom ] || {
echo 'Nothing to do.'
exit 0
}
# Loop through all the files in the bom.
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom \
| while read i; do
# Remove each file listed in the bom.
rm /usr/local/${i}
done
# Remove directories related to node.js.
rm -rf /usr/local/lib/node \
/usr/local/lib/node_modules \
/var/db/receipts/org.nodejs.*
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment