How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

前端 未结 28 2270
难免孤独
难免孤独 2020-11-21 05:28

My version of node is always v0.6.1-pre even after I install brew node and NVM install v0.6.19.

My node version is:



        
相关标签:
28条回答
  • 2020-11-21 06:11
    1. First:

      lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do  sudo rm /usr/local/${f}; done
      
      sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
      
    2. To recap, the best way (I've found) to completely uninstall node + npm is to do the following:

      go to /usr/local/lib and delete any node and node_modules

      cd /usr/local/lib
      
      sudo rm -rf node*
      
    3. go to /usr/local/include and delete any node and node_modules directory

      cd /usr/local/include
      
      sudo rm -rf node*
      
    4. if you installed with brew install node, then run brew uninstall node in your terminal

      brew uninstall node
      
    5. check your Home directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there

      go to /usr/local/bin and delete any node executable

      cd /usr/local/bin
      
      sudo rm -rf /usr/local/bin/npm
      
      ls -las
      
    6. You may need to do the additional instructions as well:

      sudo rm -rf /usr/local/share/man/man1/node.1
      
      sudo rm -rf /usr/local/lib/dtrace/node.d
      
      sudo rm -rf ~/.npm
      

    Source: tonyMtz

    0 讨论(0)
  • 2020-11-21 06:13

    Docker - alternative approach

    Docker is some-kind of super-fast virtual machine which can be use to run tools like node (instead install them directly on mac-os). Advantages to do it are following

    • all stuff ('milions' node files) are install inside docker image/container (they encapsulated in few inner-docker files)

    • you can map your mac directory with project to your docker container and have access to node - but outside docker, mac-os sytem don't even know that node is installed. So you get some kind of 'virtual' console with available node commands which can works on real files

    • you can easily kill node by find it by docker ps and kill by docker rm -f name_or_num

    • you can easily uninstall docker image/containers by one command docker rmi ... and get free space - and install it again by run script (below)

    • your node is encapsulated inside docker and don't have access to whole system - only to folders you map to it

    • you can run node services and easily map they port to mac port and have access to it from web browser

    • you can run many node versions at the same time

    • in similar way you can install other tools like (in many versions in same time): php, databases, redis etc. - inside docker without any interaction with mac-os (which not notice such software at all). E.g. you can run at the same time 3 mysql db with different versions and 3 php application with different php version ... - so you can have many tools but clean system

    • TEAM WORK: such enviroment can be easily cloned into other machines (and even to windows/linux systems - with some modifications) and provide identical docker-level environment - so you can easily set up and reuse you scripts/dockerfiles, and setup environment for new team member in very fast way (he just need to install docker and create similar folder-structure and get copy of scripts - thats all). I work this way for 2 year and with my team - and we are very happy

    Instruction

    • Install docker using e.g. this instructions

    • Prepare 'special' directory for work e.g. my directory is /Users/kamil/work (I will use this directory further - but it can be arbitrary) - this directory will be 'interface' between docker containers and your mac file ststem. Inside this dir create following dir structure:

      /Users/kamil/work/code - here you put your projects with code

      /Users/kamil/work/tools

      /Users/kamil/work/tools/docker-data - here we map containers output data like logs (or database files if someone ouse db etc.)

      /Users/kamil/work/tools/docker

      /Users/kamil/work/tools/docker/node-cmd - here we put docker node scripts

    • inside tools create file .env which will contain in one place global-paths used in other scripts

      toolspath="/Users/kamil/work/tools"
      codepath="/Users/kamil/work/code"
      workpath=/Users/kamil/work

    • innside dir ../node-cmd create file dockerfile with following content

      # default  /var/www/html (mapped to .../code folder with projects)
      FROM node
      
      WORKDIR /work
      
      # Additional arbitrary tools (ng, gulp, bower)
      RUN npm install -g n @angular/cli bower gulp grunt
      
      CMD while true; do sleep 10000; done
      
      # below ports are arbitrary
      EXPOSE 3002 3003 3004 4200

    • innside dir ../node-cmd create file run-container with following content (this file should be executable e.g. by chmod +x run-container) - (notice how we map port-s and directories form external 'world' to internal docker filesystem)

      set -e
      cd -- "$(dirname "$0")" # this script dir (not set on doubleclick)
      source ../../.env
      toolsdir=$toolspath/docker-data
      workdir=$workpath
      
      if [ ! "$(docker ps | grep node-cmd)" ] 
      then 
        docker build -t node-cmd .
        docker rm -f node-cmd |:
        docker run -d --name node-cmd -p 4200:4200 -p 4201:4201 -p 3002:3002 -p 3003:3003 -p 3004:3004 -v $toolsdir/node-cmd/logs:/root/.npm/_logs -v $workdir:/work node-cmd
      fi

    • ok now you can add some project e.g. work/code/myProject and add to it following file 'run-cmd' (must be executable)

      cd -- "$(dirname "$0")"
      ../../tools/docker/node-cmd/run-container
      docker exec -it node-cmd bash -c "cd /work/code/myProject; bash"

    • then if you run above script (by double-click), you will see console with available node commands in project directory e.g. npm install

    • to run project in background (e.g some serwice) e.g. run web-server angular-cli application you can use following script (named run-front -must be executable) - (you must also edit /etc/hosts file to add proper domain)

      cd -- "$(dirname "$0")"
      open "http://my-angular.local:3002"
      ../../tools/docker/node-cmd/run-container
      docker exec -it node-cmd  /bin/sh -c "cd /work/code/my-angular-project; npm start"
      cat         # for block script and wait for user ctrl+C

    0 讨论(0)
  • 2020-11-21 06:15

    Additional to the main answer I needed to remove all npm instances found in:

    rm -rf /usr/local/share/man/man1/npm*
    
    0 讨论(0)
  • 2020-11-21 06:16

    If you have already installed nvm then execute the following commands

    • nvm deactivate - This will remove /.nvm/*/bin from $PATH
    • nvm list - To list out all the versions of node installed in the system
    • nvm uninstall <version> in you can specify all the versions you want to uninstall.

    It is always a good that you install node using nvm and uninstall using nvm rather than brew .

    This solution worked for me.

    Additional Commands

    • which node to know the path of node installed in your system. You can rm this directory to uninstall node manually. Then you may need to adjust the PATH file accordingly.
    0 讨论(0)
  • 2020-11-21 06:16

    First of all, you need to deactivate node: (mac) after install new node version.

    nvm deactivate
    

    This is removed /Users/user_name/.nvm/*/bin from $PATH

    And after that node was updated

    node --version
    v10.9.0
    
    0 讨论(0)
  • 2020-11-21 06:16

    In my case none of the other answers worked because I previously downgraded to node8. So instead of doing above, following worked for me:

    which node
    

    which returned /usr/local/bin/node@8 instead of /usr/local/bin/node

    so i executed this command:

    brew uninstall node@8
    

    which worked and then downloaded latest pkg from official site and installed. After that I had to close my terminal and start again to access new version

    0 讨论(0)
提交回复
热议问题