How to npm uninstall

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 4, 2026

Quick Answer: To uninstall an npm package, you use the `npm uninstall` command followed by the package name. For global packages, add the `-g` flag. This command removes the package from your `node_modules` directory and updates your `package.json` and `package-lock.json` files accordingly.

Key Facts

Overview

When developing Node.js applications, you often need to add or remove libraries (packages) as your project evolves. The Node Package Manager (npm) is the default package manager for Node.js, and it provides straightforward commands for managing these dependencies. One of the essential tasks is removing a package that is no longer needed. This process ensures your project remains clean, efficient, and avoids unnecessary bloat.

The `npm uninstall` command is the counterpart to `npm install`. It serves to remove packages from your project. Understanding how to use it correctly is crucial for maintaining healthy project dependencies. This guide will walk you through the common scenarios and best practices for uninstalling npm packages.

Uninstalling Local Packages

Most often, you'll be uninstalling packages that are installed locally within your project. These are the packages listed in your `package.json` file under `dependencies` or `devDependencies`. To uninstall a local package, navigate to your project's root directory in your terminal (the directory containing `package.json`) and run the following command:

npm uninstall <package_name>

For example, if you wanted to uninstall the popular utility library 'lodash', you would type:

npm uninstall lodash

When you run this command, npm performs several actions:

Uninstalling Global Packages

Sometimes, you might install packages globally. These are typically command-line tools that you want to use across multiple projects or from any directory on your system, such as `nodemon` or `create-react-app`. To uninstall a globally installed package, you use the `-g` flag with the `npm uninstall` command:

npm uninstall -g <package_name>

For instance, to uninstall `nodemon` globally:

npm uninstall -g nodemon

Similar to local uninstalls, this removes the package from npm's global installation directory and updates any relevant global configuration files.

Uninstalling Multiple Packages

If you need to uninstall several packages at once, you can list them separated by spaces:

npm uninstall lodash express chalk

This will remove all three specified packages from your local project.

Uninstalling All Packages

In some scenarios, you might want to remove all dependencies listed in your `package.json`. You can achieve this by running the uninstall command without any package name:

npm uninstall

This command is useful if you're cleaning up a project or want to reinstall all dependencies from scratch to ensure a clean state. It will remove all directories within `node_modules` and update `package.json` and `package-lock.json` accordingly.

Troubleshooting Common Issues

Package not found: Ensure you have spelled the package name correctly and that you are in the correct directory (project root for local, or no specific directory needed for global). Also, verify if the package was actually installed in the first place.

Permissions errors: If you encounter permission errors, especially with global installations, you might need to run your terminal with administrator privileges (e.g., using `sudo` on Linux/macOS or 'Run as administrator' on Windows). However, it's generally recommended to configure npm to use a different directory for global installations to avoid permission issues altogether.

Conflicting dependencies: Sometimes, uninstalling a package might cause issues if other packages depend on it. npm usually handles this gracefully, but if you notice unexpected errors after an uninstall, you might need to investigate the dependency tree using `npm ls` or `npm list`.

Best Practices

By following these steps and understanding the commands, you can effectively manage your project's dependencies using `npm uninstall`.

Sources

  1. npm-uninstall | npm DocsCC-BY-NC-4.0
  2. Folders | npm DocsCC-BY-NC-4.0
  3. The Magic Behind npm install and package-lock.jsonfair-use

Missing an answer?

Suggest a question and we'll generate an answer for it.