Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mac OS X uninstall script for packaged install of node.js

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}
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
@omarrr

This comment has been minimized.

Show comment
Hide comment
@omarrr

omarrr Jul 14, 2012

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!

omarrr commented Jul 14, 2012

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!

@Bauepete

This comment has been minimized.

Show comment
Hide comment

Bauepete commented Jan 9, 2013

Thanks.

@mhulse

This comment has been minimized.

Show comment
Hide comment
@mhulse

mhulse Feb 19, 2013

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

mhulse commented Feb 19, 2013

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

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Mar 25, 2013

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

ghost commented Mar 25, 2013

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

@Jurawa

This comment has been minimized.

Show comment
Hide comment
@Jurawa

Jurawa Sep 24, 2013

Awesome. Worked great, thanks!

Jurawa commented Sep 24, 2013

Awesome. Worked great, thanks!

@tezca-antisol

This comment has been minimized.

Show comment
Hide comment
@tezca-antisol

tezca-antisol Oct 23, 2013

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

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

@roman

This comment has been minimized.

Show comment
Hide comment
@roman

roman Nov 12, 2013

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

roman commented Nov 12, 2013

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

@denji

This comment has been minimized.

Show comment
Hide comment
@denji

denji Nov 13, 2013

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

nodejs/node-v0.x-archive#6141

denji commented Nov 13, 2013

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

nodejs/node-v0.x-archive#6141

@taoeffect

This comment has been minimized.

Show comment
Hide comment
@taoeffect

taoeffect Nov 25, 2013

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

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

@ravs

This comment has been minimized.

Show comment
Hide comment
@ravs

ravs Jan 6, 2014

Thanks, nice stuff.

ravs commented Jan 6, 2014

Thanks, nice stuff.

@djdiaz

This comment has been minimized.

Show comment
Hide comment
@djdiaz

djdiaz Jan 13, 2014

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.

djdiaz commented Jan 13, 2014

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.

@thayneclark

This comment has been minimized.

Show comment
Hide comment
@thayneclark

thayneclark May 13, 2014

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

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

@ivancevich

This comment has been minimized.

Show comment
Hide comment
@ivancevich

ivancevich May 31, 2014

Excellent job. Thanks!

Excellent job. Thanks!

@ddo

This comment has been minimized.

Show comment
Hide comment
@lrestifo

This comment has been minimized.

Show comment
Hide comment
@lrestifo

lrestifo Oct 20, 2014

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

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

@poliveira89

This comment has been minimized.

Show comment
Hide comment
@poliveira89

poliveira89 May 4, 2015

For now, it seems to be executed successfully! 👍 (For me)

For now, it seems to be executed successfully! 👍 (For me)

@TanayGahlot

This comment has been minimized.

Show comment
Hide comment
@TanayGahlot

TanayGahlot Jul 10, 2015

Dint work for me :(

Dint work for me :(

@alexserver

This comment has been minimized.

Show comment
Hide comment
@alexserver

alexserver Jul 17, 2015

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

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

@nicerobot

This comment has been minimized.

Show comment
Hide comment
@nicerobot

nicerobot Sep 9, 2015

@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 gist.githubusercontent.com host.
@alexserver That's a curious error. It implies your sudo command doesn't have execution permissions. Maybe run diskutil repairPermissions / ?

Owner

nicerobot commented Sep 9, 2015

@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 gist.githubusercontent.com host.
@alexserver That's a curious error. It implies your sudo command doesn't have execution permissions. Maybe run diskutil repairPermissions / ?

@schystz

This comment has been minimized.

Show comment
Hide comment
@schystz

schystz Sep 11, 2015

Weird, I am getting the message "Nothing to do." although org.nodejs.node.pkg.bom 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.

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

schystz commented Sep 11, 2015

Weird, I am getting the message "Nothing to do." although org.nodejs.node.pkg.bom 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.

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

@nicerobot

This comment has been minimized.

Show comment
Hide comment
@nicerobot

nicerobot Sep 13, 2015

@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/org.nodejs.node.pkg.bom too.

Owner

nicerobot commented Sep 13, 2015

@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/org.nodejs.node.pkg.bom too.

@sshmyg

This comment has been minimized.

Show comment
Hide comment
@sshmyg

sshmyg Sep 25, 2015

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

sshmyg commented Sep 25, 2015

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

@jonathanwoahn

This comment has been minimized.

Show comment
Hide comment
@jonathanwoahn

jonathanwoahn Oct 13, 2015

Thank you - this worked perfectly!

Thank you - this worked perfectly!

@linfan

This comment has been minimized.

Show comment
Hide comment
@linfan

linfan Oct 18, 2015

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

linfan commented Oct 18, 2015

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

@allangagnon

This comment has been minimized.

Show comment
Hide comment
@allangagnon

allangagnon Nov 21, 2015

Nice Work!! Thank You!!!

Nice Work!! Thank You!!!

@jaumesalatantinya

This comment has been minimized.

Show comment
Hide comment
@jaumesalatantinya

jaumesalatantinya Nov 24, 2015

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

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

@ryan-lynch

This comment has been minimized.

Show comment
Hide comment
@ryan-lynch

ryan-lynch Dec 15, 2015

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

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

@youngrrrr

This comment has been minimized.

Show comment
Hide comment
@youngrrrr

youngrrrr Dec 30, 2015

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

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

@vvardhanz

This comment has been minimized.

Show comment
Hide comment
@vvardhanz

vvardhanz Jan 2, 2016

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

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

@icetee

This comment has been minimized.

Show comment
Hide comment
@icetee

icetee Jan 9, 2016

@vvardhanz use alternative solution.

icetee commented Jan 9, 2016

@vvardhanz use alternative solution.

@Wuntenn

This comment has been minimized.

Show comment
Hide comment
@Wuntenn

Wuntenn Jan 14, 2016

Thanks!! - Great Script!!

Wuntenn commented Jan 14, 2016

Thanks!! - Great Script!!

@kevin-smets

This comment has been minimized.

Show comment
Hide comment
@kevin-smets

kevin-smets Feb 19, 2016

Running the script by pasting it into a local .sh file worked. Running it through curl did not (at least the first option described here).

However, I wanted to replace my package installed node by a brew install, but I got the following error:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
  rm '/usr/local/share/doc/node/gdbinit'

Removing it made brew link up node properly. Maybe this should be added to the removals?

(Uninstalled node v4.3.1 and installed v5.6.0 through brew)

Running the script by pasting it into a local .sh file worked. Running it through curl did not (at least the first option described here).

However, I wanted to replace my package installed node by a brew install, but I got the following error:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
  rm '/usr/local/share/doc/node/gdbinit'

Removing it made brew link up node properly. Maybe this should be added to the removals?

(Uninstalled node v4.3.1 and installed v5.6.0 through brew)

@morberg

This comment has been minimized.

Show comment
Hide comment
@morberg

morberg Feb 22, 2016

@ryan-lynch @youngrrrr The script will not start until you press return.

morberg commented Feb 22, 2016

@ryan-lynch @youngrrrr The script will not start until you press return.

@DonRichards

This comment has been minimized.

Show comment
Hide comment

Thanks!!

@AlexVentura

This comment has been minimized.

Show comment
Hide comment
@AlexVentura

AlexVentura Mar 15, 2016

Thank you I am using NodeJS package from the official website in El Capitan, then I run the script and everything seems fine.

Thank you I am using NodeJS package from the official website in El Capitan, then I run the script and everything seems fine.

@doncadavona

This comment has been minimized.

Show comment
Hide comment
@doncadavona

doncadavona Jun 22, 2016

Works like charm!
The alternative worked for me on El Capitan:

curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh

doncadavona commented Jun 22, 2016

Works like charm!
The alternative worked for me on El Capitan:

curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh
@rsaddey

This comment has been minimized.

Show comment
Hide comment
@rsaddey

rsaddey Jul 3, 2016

How about virtualising Node.js within Docker in the first place? Right now, Docker appears to be targeted towards builds and production, but IMHO it's a perfect tool to distribute, customise and share developer environments as well. I took a first (quite humble - I'm a newbie to both Docker and Node.js) approach at https://blog.saddey.net/2016/07/03/using-docker-to-create-ionic-2-pwa-developer-environment/ Does this make any sense?

rsaddey commented Jul 3, 2016

How about virtualising Node.js within Docker in the first place? Right now, Docker appears to be targeted towards builds and production, but IMHO it's a perfect tool to distribute, customise and share developer environments as well. I took a first (quite humble - I'm a newbie to both Docker and Node.js) approach at https://blog.saddey.net/2016/07/03/using-docker-to-create-ionic-2-pwa-developer-environment/ Does this make any sense?

@TheeAndre

This comment has been minimized.

Show comment
Hide comment
@TheeAndre

TheeAndre Jul 6, 2016

@doncadavona's solution worked like a charm.

@doncadavona's solution worked like a charm.

@FootballFan141

This comment has been minimized.

Show comment
Hide comment
@FootballFan141

FootballFan141 Jul 13, 2016

@doncadavona's comment worked! Thanks for this gist! 😄

@doncadavona's comment worked! Thanks for this gist! 😄

@nflowforward

This comment has been minimized.

Show comment
Hide comment
@nflowforward

nflowforward Jul 28, 2016

the screen is frozen, im trying to uninstall node js from my computer and reinstall it wt homebrew..any help will be appreciated. i have os x el capitan.

the screen is frozen, im trying to uninstall node js from my computer and reinstall it wt homebrew..any help will be appreciated. i have os x el capitan.

@Zenfeder

This comment has been minimized.

Show comment
Hide comment

Zenfeder commented Dec 8, 2016

Thanks!

@dylynthesis

This comment has been minimized.

Show comment
Hide comment
@dylynthesis

dylynthesis Dec 26, 2016

Sweet thank you!

Sweet thank you!

@naoufalmed

This comment has been minimized.

Show comment
Hide comment
@naoufalmed

naoufalmed Apr 26, 2017

I didn't try
curl -ks https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh | bash

But the alternative way worked for me on macOS Sierra (10.12.4) to uninstall Node v7.9.0.

Thank you @nicerobot!

I didn't try
curl -ks https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh | bash

But the alternative way worked for me on macOS Sierra (10.12.4) to uninstall Node v7.9.0.

Thank you @nicerobot!

@maiky15

This comment has been minimized.

Show comment
Hide comment
@maiky15

maiky15 May 11, 2017

great!
try node -v after and No such file or directory ;)

maiky15 commented May 11, 2017

great!
try node -v after and No such file or directory ;)

@srinivaswings

This comment has been minimized.

Show comment
Hide comment
@srinivaswings

srinivaswings May 18, 2017

thanks.. Great

thanks.. Great

@bklossner

This comment has been minimized.

Show comment
Hide comment
@bklossner

bklossner Jun 7, 2017

I second the "Alternative" route. It works perfectly for El Capitan. Thanks!

bklossner commented Jun 7, 2017

I second the "Alternative" route. It works perfectly for El Capitan. Thanks!

@xxd3vin

This comment has been minimized.

Show comment
Hide comment
@xxd3vin

xxd3vin Jul 19, 2017

Try with curl, no luck:

$ curl -ks https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh | bash
DISCLAIMER: USE THIS SCRIPT AT YOUR OWN RISK!
THE AUTHOR TAKES NO RESPONSIBILITY FOR THE RESULTS OF THIS SCRIPT.
Disclaimer aside, this worked for the author, for what that's worth.
Press Control-C to quit now.
Re-running the script with sudo.
You may be prompted for a password.
Password:
/usr/bin/sudo: /usr/bin/sudo: cannot execute binary file

xxd3vin commented Jul 19, 2017

Try with curl, no luck:

$ curl -ks https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh | bash
DISCLAIMER: USE THIS SCRIPT AT YOUR OWN RISK!
THE AUTHOR TAKES NO RESPONSIBILITY FOR THE RESULTS OF THIS SCRIPT.
Disclaimer aside, this worked for the author, for what that's worth.
Press Control-C to quit now.
Re-running the script with sudo.
You may be prompted for a password.
Password:
/usr/bin/sudo: /usr/bin/sudo: cannot execute binary file
@samj

This comment has been minimized.

Show comment
Hide comment
@samj

samj Oct 20, 2017

I also got sudo: cannot execute binary file and suspect it relates to the sudo sudo call (sudo itself runs, except when being run by sudo?)

samj commented Oct 20, 2017

I also got sudo: cannot execute binary file and suspect it relates to the sudo sudo call (sudo itself runs, except when being run by sudo?)

@AlexVentura

This comment has been minimized.

Show comment
Hide comment
@AlexVentura

AlexVentura Oct 25, 2017

I'm on Mac OS X High Sierra v10.13 using NodeJS v6.11.5 LTS installed with package from the official site.
I downloaded the script and then just run:

sudo ./uninstall-node.sh

And it works fine!

I'm on Mac OS X High Sierra v10.13 using NodeJS v6.11.5 LTS installed with package from the official site.
I downloaded the script and then just run:

sudo ./uninstall-node.sh

And it works fine!

@mwanjajoel

This comment has been minimized.

Show comment
Hide comment
@mwanjajoel

mwanjajoel Nov 11, 2017

Worked fine on the High Sierra v10.13.1 thanks alot!

Worked fine on the High Sierra v10.13.1 thanks alot!

@0x8BADFOOD

This comment has been minimized.

Show comment
Hide comment
@0x8BADFOOD

0x8BADFOOD Jan 9, 2018

Worked for El Capitan v10.11.16. Thank you!

Worked for El Capitan v10.11.16. Thank you!

@msjithin996

This comment has been minimized.

Show comment
Hide comment

works fine

@nicerobot

This comment has been minimized.

Show comment
Hide comment
@nicerobot

nicerobot Mar 22, 2018

I removed the curl version. It won't work and results in the sudo sudo problem mentioned above. @xxd3vin @samj

Owner

nicerobot commented Mar 22, 2018

I removed the curl version. It won't work and results in the sudo sudo problem mentioned above. @xxd3vin @samj

@roubee

This comment has been minimized.

Show comment
Hide comment
@roubee

roubee Apr 25, 2018

Worked fine in OS X El Capitan v10.11.6. Thank you :)

roubee commented Apr 25, 2018

Worked fine in OS X El Capitan v10.11.6. Thank you :)

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