Software Engineering

How to Uninstall npm packages

We typically install an npm package as follows:

npm install <package_name>

But how do we uninstall an npm package?

How to uninstall an npm package

This will uninstall an npm package that was installed in your project.

Just make sure to run the command from the root directory of your project.

npm uninstall <package_name>

This will remove the package from the node_modules directory and will also remove the reference to it from the package.json file.

How to uninstall a devDependency

If you have a package installed in the devDependency section of your package.json, then you can uninstall it as follows:

npm uninstall -D <package_name>

How to uninstall a global npm package

Sometimes we install npm packages globally, so that we can use them as command-line tools, or if we want them accessible to all projects.

This can be achieved as follows:

npm uninstall -g <package_name>

You may also ask these questions

What happens if I uninstall npm?

When you uninstall npm you are removing packages that have previously been installed by the npm install or npm i commands.

How do I uninstall npm alone?

If you would like to uninstall a specific npm package, then run the following command:

npm uninstall <package_name>

How uninstall npm react?

If you would like to uninstall a Remove Create React App:

# npm
npm uninstall -g create-react-app

# yarn
yarn global remove create-react-app

How do I uninstall and reinstall node and npm?

Delete the node and npm folders located there:

# delete node folder
rm -rf  /usr/local/bin/node

# delete npm folder
rm -rf  /usr/local/bin/npm

Once both folders are deleted, you can reinstall node and npm using the .pkg file for Mac.

If you install Node using Homebrew, then you can use brew command to uninstall it:

# uninstall node and npm
brew uninstall node

# install it again
brew install node

If you are using Linux Ubuntu, then you can remove Node using apt-get as shown below:

# uninstall node for Ubuntu
sudo apt-get remove node

# install it again
sudo apt-get install node

If you don’t want to uninstall node, then you can try to download and install npm directly using the script from

Open the terminal and run the following command:

curl -qL | sh

Typically, if you have an existing npm program installed already, the direct install will fail as shown below:

$ curl -qL | sh

# ...
# fetching:
# removing existing npm
# failed!

Seems npm direct installation won’t work for some reason.

You need to add the sudo command to the sh pipe as shown below:

curl -qL | sudo sh

If you’re using ZSH, you may see the command above suspended like this:

# zsh: suspended (tty input) sudo sh

When that happens, try to download the script first, then run it using the sudo command as follows:

# download
curl -O

# run the script using sudo
sudo sh

# after installation complete, remove the script