public
Last active

Mac OS X uninstall script for packaged install of node.js

  • Download Gist
README.md
Markdown

To run this, you can try:

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

I haven't tested this script doing it this way but i run a lot of my Gists like this so maybe this one'll work too.

Alternatively,

curl -ksO https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh
uninstall-node.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#!/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

Nice work. I forked to edit line #16 as follows:

 [ -e /var/db/receipts/org.nodejs.pkg.bom ] || {

This looks for the existence of a file (-e) instead of a folder (-d).

Once I did that it worked like a charm. Thanks!

Great script, thanks! Just FYI to anyone out there new to running shell scripts: I had to run $ chmod u+x uninstall-node.sh and then $ ./uninstall-node.sh before it worked for me. Also, there's a question on Stack related to this code if it is of help to anyone (might be a good place for comments, seeing as how GitHub does not notify anyone (at this time) when comments are posted to Gists).

Had to use mhulse's method to get it to work, thanks though!

Awesome. Worked great, thanks!

I don't know if is really necessary, but i thing the script should delete ~/.node-gyp y ~/.npm from the local user, maybe even test is there are that directories in other users so you completely remove all what node.js creates

What is the purpose of (( ${#} > 0 )) ?

node 0.11.x forgot delete /usr/local/share/systemtap
if empty (/usr/local/share/systemtap + /usr/local/share/systemtap/tapset)

https://github.com/joyent/node/issues/6141

@roman, it's a hack to skip the first block on the next run.

Thanks, nice stuff.

Thanks! Doesn't work when piped directly from curl to the shell as there is no command line to test in the first block. Might work with "sudo bash" instead, but I didn't bother to hash it out.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.