Uninstalling and reinstalling Node.js on a Mac can be a complex process, especially when using package managers like Homebrew or version managers like NVM. In this tutorial, we’ll walk you through the steps to completely uninstall Node.js, npm, and NVM from your system and then reinstall them from scratch.
Step 1: Uninstalling Node.js
To uninstall Node.js, you need to remove all associated files and directories from your system. The following commands will help you do so:
- Remove Node.js and its dependencies using Homebrew (if installed):
brew uninstall node
* Remove the `node` executable and other related files:
```bash
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
Alternatively, you can break down this command into smaller parts for better understanding:
```bash
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/share/man/man1/node*
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
### Step 2: Removing NVM
If you're using NVM, you'll need to remove it as well. To do so, follow these steps:
* Remove the NVM configuration files:
```bash
rm -rf ~/.nvm
- If you have any node versions installed with NVM, remove them manually or use the following command (replace
vX.X.X
with your actual version):
nvm uninstall vX.X.X
### Step 3: Cleaning Up
After removing Node.js and NVM, it's essential to clean up any remaining files. Run the following commands:
* Remove any local node installations:
```bash
sudo rm -rf /usr/local/lib/node
sudo rm -rf /usr/local/lib/node_modules
- If you have any
node
ornpm
executables left, remove them manually:
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/bin/npm
### Step 4: Reinstalling Node.js with NVM
To reinstall Node.js using NVM, follow these steps:
* Install NVM by running the installation script (replace `v0.39.0` with the latest version):
```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
- Restart your terminal or run
source ~/.bashrc
to apply the changes. - Install the desired Node.js version using NVM (replace
vX.X.X
with your preferred version):
nvm install vX.X.X
### Step 5: Verifying the Installation
To verify that Node.js and npm are installed correctly, run the following commands:
```bash
node -v
npm -v
You should see the versions of Node.js and npm that you just installed.
By following these steps, you’ll be able to completely uninstall Node.js, npm, and NVM from your Mac and then reinstall them from scratch using NVM.