Mac installation and uninstallation of node and npm

1. Official website download

Visit the nodejs official website, click on the stable version, and download
https://nodejs.org/en
Please add image description

2. Installation

Double-click the file you just downloaded and follow the steps to install it by default.
Please add image description

3. Verification

After the installation is complete, open the terminal

npm -v

node -v

The version information appears as shown below, indicating that the installation was successful.
Please add image description

4. Environment configuration

Open the Mac terminal and configure global environment variables

vim .bash_profile

Add the following line of code, (Mac node and npm executable files are in the /usr/local/bin/ directory)

Press i to enter the following

PATH=$PATH:/usr/local/bin/

Press ESC and enter:

:wq //保存并退出

At this point, reopen the terminal and enter node to enter the node environment.Please add image description

5. Uninstall node and npm

1. Enter the following commands in the terminal in sequence

Note: $USER, remember to delete it under the account you logged in; you can also go to the corresponding directory to check whether there are these files.

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

2. Verification

Return: zsh: command not found: npm, then success

node -v 
npm -v

Guess you like

Origin blog.csdn.net/qq_34681580/article/details/130240502