I installed NodeJS from pkg file on my Mac. Now I need to uninstall it. Tell me please how to do it. I tried to remove files from this list:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom
But node is still on my computer.
In order to delete the 'native' node.js installation, I have used the method suggested in previous answers sudo npm uninstall npm -g
, with additional sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
.
BUT, I had to also delete the following two directories:
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
Only after that I could install node.js with Homebrew.
ls /var/db/receipts/org.node*
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.npm.pkg.bom
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read i; do sudo rm /${i}; done
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.npm.pkg.bom | while read i; do sudo rm /${i}; done
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf /var/db/receipts/org.nodejs.*
which node
which npm
I took AhrB's list, while appended three more files. Here is the full list I have used:
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/systemtap/tapset/node.stp
sudo rm /usr/local/lib/dtrace/node.d
# In case you want to reinstall node with HomeBrew:
# brew install node
This is the full list of commands I used (Many thanks to the posters above):
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
brew install node
Following previous posts, here is the full list I used
sudo npm uninstall npm -g
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
brew install node
A little convenience script expanding on previous answers.
#!/bin/bash
# Uninstall node.js
#
# Options:
#
# -d Actually delete files, otherwise the script just _prints_ a command to delete.
# -p Installation prefix. Default /usr/local
# -f BOM file. Default /var/db/receipts/org.nodejs.pkg.bom
CMD="echo sudo rm -fr"
BOM_FILE="/var/db/receipts/org.nodejs.pkg.bom"
PREFIX="/usr/local"
while getopts "dp:f:" arg; do
case $arg in
d)
CMD="sudo rm -fr"
;;
p)
PREFIX=$arg
;;
f)
BOM_FILE=$arg
;;
esac
done
lsbom -f -l -s -pf ${BOM_FILE} \
| while read i; do
$CMD ${PREFIX}/${i}
done
$CMD ${PREFIX}/lib/node \
${PREFIX}/lib/node_modules \
${BOM_FILE}
Save it to file and run with:
# bash filename.sh
The following worked after trial and error, and these directories were not writable so, I removed them and finally was able to get node & npm replaced.
sudo rm -rf /usr/local/share/systemtap
sudo rm -rf /usr/local/share/doc/node
sudo rm -rf /usr/local/Cellar/node/9.11.1
brew install node
==> Downloading https://homebrew.bintray.com/bottles/node-9.11.1.high_sierra.bottle.tar.gz
Already downloaded: /Users/xxx/Library/Caches/Homebrew/node-9.11.1.high_sierra.bottle.tar.gz
==> Pouring node-9.11.1.high_sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
/usr/local/Cellar/node/9.11.1: 5,125 files, 49.7MB
node -v
v9.11.1
npm -v
5.6.0
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/59c25be64e5555415726bfa824ae41ae1b4539b9/uninstall-node.sh
chmod +x ./uninstall-node.sh
sudo ./uninstall-node.sh > tester.txt
rm uninstall-node.sh
It works on Mac OSX Big Sur (11.4+).
If you installed Node from their website, try this:
sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}
This worked for me, but if you have any questions, my GitHub is 'mnafricano'.
I also installed via .pkg
, I had a lot of permission errors lately and wanted to use nvm
so had to uninstall the current version. Found the below script from here
sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}
I ran:
Coded into gist 2697848
Update It seems the receipts
.bom
file name may have changed so you may need to replaceorg.nodejs.pkg.bom
withorg.nodejs.node.pkg.bom
in the above. The gist has been updated accordingly.