Uninstall Node.js on Mac

To uninstall Node.js on Mac, you can choose the following two methods:

  1. Uninstall Node.js using the command line

Step 1: Open the terminal and enter the following command to display the installation path of Node.js:

which node

After executing this command, the installation path will be displayed: /usr/local/bin/node

Step 2: Enter the following command to delete Node.js related files:

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

This command will delete the Node.js executable file, npm package manager, man page, DTrace trace file and related files in the user directory.

Step 3: Determine whether to completely uninstall Node.js. Enter the following command in the terminal:

node -v

If "command not found" is displayed, it means that it has been uninstalled.

  1. Uninstall Node.js using the Node.js command tool

Using the Node.js command tool simplifies the steps to uninstall Node.js, as follows:

Step 1: Download and install npm of the Node version you want to use.

curl https://npmjs.org/install.sh | sh

This command will install the latest version of npm on the system.

Step 2: Use npm to uninstall Node.js.

sudo npm uninstall npm -g

This command will uninstall npm.

Step 3: Uninstall Node.js using the official Node.js package.

sudo rm /usr/local/bin/node

This command will delete the Node.js executable file.

It is recommended to use the first method to uninstall Node.js, because the commands in it can ensure that all related files are completely deleted, ensuring that there will be no problems with the next reinstallation.

It should be noted that before uninstalling Node.js, back up the project code and related configuration files to prevent accidental deletion.

Guess you like

Origin blog.csdn.net/tdjqqq/article/details/134135688