How do I uninstall nodejs installed from pkg (Mac OS X)?

前端 未结 10 1842
别那么骄傲
别那么骄傲 2020-11-30 16:32

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

相关标签:
10条回答
  • 2020-11-30 16:47

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

    0 讨论(0)
  • 2020-11-30 16:47

    Use npm to uninstall. Just running sudo npm uninstall npm -g removes all the files. To get rid of the extraneous stuff like bash pathnames run this (from nicerobot's answer):

    sudo rm -rf /usr/local/lib/node \ /usr/local/lib/node_modules \ /var/db/receipts/org.nodejs.*

    0 讨论(0)
  • 2020-11-30 16:49

    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.

    0 讨论(0)
  • 2020-11-30 16:50

    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
    
    0 讨论(0)
  • 2020-11-30 16:52

    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
    
    0 讨论(0)
  • 2020-11-30 16:52

    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
                                                                        
    0 讨论(0)
提交回复
热议问题