Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active January 19, 2023 12:20
Embed
What would you like to do?
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
@DonRichards
Copy link

Thanks!!

@alexventuraio
Copy link

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

@doncadavona
Copy link

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
Copy link

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
Copy link

@doncadavona's solution worked like a charm.

@FootballFan141
Copy link

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

@nflowforward
Copy link

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
Copy link

Zenfeder commented Dec 8, 2016

Thanks!

@dylanpluto
Copy link

Sweet thank you!

@naoufalmed
Copy link

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
Copy link

maiky15 commented May 11, 2017

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

@srinivaswings
Copy link

thanks.. Great

@bklossner
Copy link

bklossner commented Jun 7, 2017

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

@xx7y7xx
Copy link

xx7y7xx 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
Copy link

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

@alexventuraio
Copy link

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
Copy link

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

@0x8BADFOOD
Copy link

Worked for El Capitan v10.11.16. Thank you!

@msjithin996
Copy link

works fine

@nicerobot
Copy link
Author

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

@roubee
Copy link

roubee commented Apr 25, 2018

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

@GregHilston
Copy link

This gist is referenced by this SO post, if you run into problems: https://stackoverflow.com/questions/35249204/node-already-installed-its-just-not-linked

@jaykhimani
Copy link

Thanks for the script. In addition to the script, I also had to remove /usr/local/bin/node

@Teddy95
Copy link

Teddy95 commented Aug 4, 2019

Script works fine for me after changing line 23 from

# this tries to delete /usr/local/./usr/local/.....
rm -v /usr/local/${i}

to

# this works fine :)
rm -v ${i:1}

Mac OS Mojave 10.14.6

@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