Skip to content
Create a gist now

Instantly share code, notes, and snippets.

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

To run this, you can try:

curl -ks | 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.


curl -ksO
chmod +x ./
(( ${#} > 0 )) || {
echo "Disclaimer aside, this worked for the author, for what that's worth."
echo 'Press Control-C to quit now.'
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; do
[ -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}
# Remove directories related to node.js.
rm -vrf /usr/local/lib/node \
/usr/local/lib/node_modules \
exit 0

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

 [ -e /var/db/receipts/ ] || {

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 and then $ ./ 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).

Unknown commented

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)



@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.


Thanks, worked great. And thanks for the tip mhulse.


Excellent job. Thanks!


Worked a treat for me just by saving the script locally and chmod 755 the resulting file


For now, it seems to be executed successfully! :+1: (For me)


Dint work for me :(


/usr/bin/sudo: /usr/bin/sudo: cannot execute binary file


@TanayGahlot Sorry, if you were using the curl method, the URLs were using the old gist URLs so I had to update them to the host.
@alexserver That's a curious error. It implies your sudo command doesn't have execution permissions. Maybe run diskutil repairPermissions / ?


Weird, I am getting the message "Nothing to do." although is existing in the /var/db/receipts directory. I also tried @omarrr's solution and even executing the script using sudo but that didn't help.

I tried executing the command lsbom -f -l -s -pf /var/db/receipts/ from the command line and it works. But if its inside the sh script I get the message can't open /var/db/receipts/ No such file or directory.


@schystz It looks like node's .bom file name may have changed since i originally coded this. I'll update it to look for /var/db/receipts/ too.


What about org.nodejs.node.npm.pkg.plist org.nodejs.pkg.plist?
Is it necessary to remove this ones?


Thank you - this worked perfectly!


Nice job!!
Works perfectly for me. Finally removed the nodejs version installed by pkg installer.


Nice Work!! Thank You!!!


Thank you I just run under el capitan and everything seems fine


Seems to freeze terminal for me after echo'ing Press Control-C to quit now.


having the same problem as @ryan-lynch. after letting it run for a few minutes, I just killed the program.


/usr/bin/sudo: /usr/bin/sudo: cannot execute binary file @nicerobot


@vvardhanz use alternative solution.


Thanks!! - Great Script!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.