Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active November 13, 2024 20:27
Show Gist options
  • Save nicerobot/2697848 to your computer and use it in GitHub Desktop.
Save nicerobot/2697848 to your computer and use it in GitHub Desktop.
Mac OS X 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/nicerobot/2697848/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).
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.
rm -v /usr/local/${i#/usr/local/}
done
}
done
# Remove directories related to node.js.
rm -vrf /usr/local/lib/node \
/usr/local/lib/node_modules \
/var/db/receipts/org.nodejs.*
exit 0
@JakobJingleheimer
Copy link

macOS Big Sur 11.1

I had to manually delete these after:

  • /usr/local/bin/node
  • /usr/local/bin/npm
  • /usr/local/bin/npx

Aside from that, seems to have done the trick.

@andersk
Copy link

andersk commented Apr 9, 2021

It seems that lsbom (now?) outputs paths beginning with ./usr/local/ rather than /usr/local/. Therefore, line 23 needs to be adjusted:

-      rm -v /usr/local/${i#/usr/local/}
+      rm -v /usr/local/${i#./usr/local/}

@nicerobot
Copy link
Author

Indeed, it looks like they changed the output. That's unfortunate.

@ryangatchalian912
Copy link

ryangatchalian912 commented Jul 20, 2021

You can use my forked gist:
https://gist.github.com/ryangatchalian912/75c6894c3f3143fef366d25eb63437ab

Copy and paste these commands into your Terminal:

curl -ksO https://gist.githubusercontent.com/ryangatchalian912/75c6894c3f3143fef366d25eb63437ab/raw/9345866b0f3d0bb0ab1bebbe721a811f15a2adbe/uninstall-node.sh
chmod +x ./uninstall-node.sh
sudo ./uninstall-node.sh
rm uninstall-node.sh

It works on Mac OSX Big Sur (11.4).

@jk62
Copy link

jk62 commented Dec 4, 2021

after running the script first time i ran node -v command which gave following output:

(base) jaikishansharma@Jaikishans-MacBook-Air ~ % node -v
v16.10.0

and when i ran this script again it gave following output:

(base) jaikishansharma@Jaikishans-MacBook-Air ~ % curl -ksO https://gist.githubusercontent.com/ryangatchalian912/75c6894c3f3143fef366d25eb63437ab/raw/9345866b0f3d0bb0ab1bebbe721a811f15a2adbe/uninstall-node.sh
chmod +x ./uninstall-node.sh
sudo ./uninstall-node.sh
rm uninstall-node.sh
Password:

Node.js not found. Nothing to do.
can anyone explain how node -v still indicate that node.js is still installed on my mac

@nicerobot
Copy link
Author

@jk62 There are multiple ways to install Node.js these days. This script was created to uninstall the MacOS package installer version of Node.js. If you install using brew or nvm or some other package/version manager like that, this script isn't useful. To know whether this script makes sense, try the following to give a clue of how it was installed:

which node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment