Skip to content

Instantly share code, notes, and snippets.

@chriswayg
Forked from nicerobot/README.md
Last active February 25, 2024 02:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswayg/cd923e933062f0c053a417fa6bf1094e to your computer and use it in GitHub Desktop.
Save chriswayg/cd923e933062f0c053a417fa6bf1094e to your computer and use it in GitHub Desktop.
Modified macOS uninstall script for packaged install of node.js from https://stackoverflow.com/a/9287292/23056

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment