Created
November 21, 2022 09:44
-
-
Save koola/451fa1b4f2b9af7833f107584a356593 to your computer and use it in GitHub Desktop.
Mac OS X uninstall script for default node dmg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
(( ${#} >= 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 that Node.js bom exists. Otherwise, don't do anything. | |
[ -e /var/db/receipts/org.nodejs.node.pkg.bom ] || { | |
echo '>>> Node.js not found. Nothing to do.' | |
exit 0 | |
} | |
# Verify that the npm bom exists. Otherwise, don't do anything. | |
[ -e /var/db/receipts/org.nodejs.npm.pkg.bom ] || { | |
echo '>>> npm not found. Nothing to do.' | |
exit 0 | |
} | |
for bom in org.nodejs.node.pkg.bom org.nodejs.npm.pkg.bom; do | |
receipt=/var/db/receipts/${bom} | |
echo ">>> Removing bom files from ${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. | |
rm -v /usr/local/${i#./usr/local/} | |
done | |
} | |
done | |
# Remove files and directories related to Node.js and npm. | |
echo '>>> Removing Node.js and npm files and directories...' | |
sudo rm -rfv /usr/local/lib/node_modules \ | |
/usr/local/lib/node \ | |
/usr/local/include/node \ | |
/usr/local/share/doc/node \ | |
/usr/local/share/man/{man1,man5}/npm* \ | |
/usr/local/share/man/{man1,man5}/npx* \ | |
/usr/local/share/man/{man1,man5}/install* \ | |
/usr/local/share/man/{man1,man5}/folders* \ | |
/usr/local/share/man/{man1,man5}/package-json* \ | |
/usr/local/share/man/{man1,man5}/package-lock* \ | |
/usr/local/share/man/{man1,man5}/shrinkwrap* \ | |
/usr/local/share/man/man7 \ | |
/usr/local/bin/{npx,npm,node} \ | |
/var/db/receipts/org.nodejs.* \ | |
~/.node-gyp \ | |
~/.npm | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute as
sudo bash -c "$(wget -qO- https://gist.githubusercontent.com/koola/451fa1b4f2b9af7833f107584a356593/raw/f61c261e1a717f70d9cc10642a42867c474c24ac/uninstall_node.sh)"