How to completely uninstall and re-install Node.js and npm in Mac OS
In this tutorial, we are going to learn how to uninstall and re-install node and npm in mac os using terminal and nvm (node version manager).
Uninstalling Node and Npm
To completely uninstall node and npm follow the below steps.
Open your terminal.
Now, run the below command by hitting the enter key.
curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh chmod +x ./uninstall-node.sh ./uninstall-node.sh rm uninstall-node.sh
- Go to the
- At final run the following commands, to delete any node or node_modules inside the
sudo rm -rf /usr/local/bin/npm sudo rm -rf /usr/local/bin/node
- Verify if the node is completely uninstalled or not using
If the output shows
command not found then you are successfully uninstalled.
Installing node and npm using nvm
We are using the node version manager (nvm) to download and install the latest version of node.js (with npm included).
- Run the following command in your terminal to install the nvm.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
- If your using bash or zsh, you need to add the following code to
bashrc file in vscode use
code ~/.bashrc command.
zshrc file in vscode use
code ~/.zshrc command.
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
- Verify the nvm installation by running the below command.
nvm --version # 0.35.3
If the output shows a version number then you are successfully installed.
- Now, run the following command to download and install the latest version of node.
nvm install node
If you want to install a long term support (LTS) version use this command.
nvm install --lts
or a specific version.
nvm install 12.1.4
- To use the node, we need to set the default node version by using this command.
nvm alias default node
- Verify the node and npm installation.
node -v npm -v
You can also learn, How to uninstall node and npm from Windows.