How to uninstall npm packages?
Tags: node, npm, javascript
Published: 2021-06-16 14:13:07

---
title: How to uninstall npm packages?
published: true
date: 2021-03-15 00:00:00 UTC
tags: node, npm, javascript
canonical_url: https://www.mariokandut.com/how-to-uninstall-npm-packages/
---

Installing and uninstalling dependencies are core parts of working with any Node.js project. If you are just starting with Node.js, have a look at this article - [how to install npm packages](https://www.mariokandut.com/how-to-install-npm-packages/).

There are two ways to uninstall packages - manually or automatically.

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#uninstalling-dependencies)Uninstalling dependencies

To uninstall a package, you have to remove it from your `node_modules` folder (that's where the code lives), and from `package.json` (listed there as a project dependency). If you only remove it in the `node_modules` folder and run `npm install` it will be reinstalled, and if you only remove the package entry in the `package.json` the package still exists in the `node_modules` folder.

But don't worry. The `npm uninstall` command will do both of it. Follow these steps for uninstalling dependencies:

1. Identify the package you want to uninstall by looking in your package.json.
2. Run the following command with the name of the package, or multiple packages separated by spaces:

```
npm uninstall <package1> <package2>
```

After successfully running the command, the NPM CLI will uninstall the package and print information to the terminal about how many packages were removed. Uninstalling removes the specified package, and all the packages it used internally as dependencies.

1. Verify that it has been removed in the `package.json`, this depends on your installed npm version. Since npm version 5 (released in 2017) installing or uninstalling a dependency will update the `package.json` automatically. Previously it was required when installing a package to add the `--save` flag to add the package entry in package.json.

### [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#uninstall-global-packages)Uninstall global packages

If you've installed a package globally, you can uninstall it by passing the `-g` flag when uninstalling. For example, if you have Gatsby CLI globally installed and want to remove it:

```
npm uninstall -g gatsby
```

A helpful command is `npm prune`, which cleans extraneous packages in your `node_modules` folder. More details can be found in a future article.

## [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#tldr)TL;DR

- Delete packages automatically with `npm uninstall`.
- Avoid deleting packages manually.
- Do not check your `node_modules` in version control.
- Clean up `node_modules` with `npm prune` command.

Thanks for reading and if you have any **questions** , use the **comment** function or **send me a message** **[@mariokandut](https://www.twitter.com/mariokandut)**.

If you want to know more about **[Node](https://www.mariokandut.com/tags/node)**, have a look at these [Node Tutorials](https://www.mariokandut.com/tags/node).

### [<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#references-and-big-thanks)References (and Big thanks):

[HeyNode](https://heynode.com), [NPM Documentation - install](https://docs.npmjs.com/cli/install), [NPM Documentation - uninstall](https://docs.npmjs.com/cli/uninstall)