Home >Web Front-end >JS Tutorial >How Do I Completely Uninstall and Reinstall Node.js and npm on macOS to Resolve Persistent Version Conflicts?

How Do I Completely Uninstall and Reinstall Node.js and npm on macOS to Resolve Persistent Version Conflicts?

Barbara Streisand
Barbara StreisandOriginal
2024-12-25 00:43:15564browse

How Do I Completely Uninstall and Reinstall Node.js and npm on macOS to Resolve Persistent Version Conflicts?

Uninstalling and Reinstalling Node.js on Mac OS X

Problem:

You encounter a persistent phantom version of Node.js (v0.6.1-pre) despite installing newer versions using Brew and NVM. You wish to completely remove Node.js, npm, and NVM and reinstall them from the beginning.

Solution:

  1. Locate and Delete Phantom Folders:

    • Navigate to the /Users//local folder and delete any include or lib folders containing node or node_modules.
  2. Uninstall Node.js via Brew:

    • Open Terminal and run:

      brew uninstall node
  3. Remove NVM Modifications:

    • Open the .bashrc file in your Home directory.
    • Remove any NVM-related lines that modify the PATH variable.
  4. Uninstall Node.js and npm (Optional):

    • Remove any remaining node, node_modules, and npm files from the following locations:

      • /usr/local/lib
      • /usr/local/include
      • /usr/local/bin
      • /usr/local/share/man/man1
      • Your Home directory
  5. Reinstall Node.js and npm:

    • Download and install NVM.
    • Install Node.js using NVM:

      nvm install node

Additional Notes:

  • If necessary, use the following commands to remove additional artifacts:

    sudo rm -rf \
    /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
  • Reinstalling Node.js should also reinstall npm.
  • After completing the reinstallation, verify the installed versions:

    node -v
    npm -v

The above is the detailed content of How Do I Completely Uninstall and Reinstall Node.js and npm on macOS to Resolve Persistent Version Conflicts?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn