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
Key Facts
- The primary command is `npm uninstall <package_name>`.
- To remove a globally installed package, use `npm uninstall -g <package_name>`.
- Uninstalling also removes the package from `dependencies` or `devDependencies` in `package.json`.
- The `package-lock.json` file is also updated to reflect the removal.
- Running `npm uninstall` without a package name will uninstall all packages listed in `package.json`.
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:
- It removes the package's directory from the `node_modules` folder within your project.
- It removes the corresponding entry for the package from the `dependencies` or `devDependencies` section of your `package.json` file.
- It updates the `package-lock.json` file to reflect the removal, ensuring consistent installations across different environments.
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
- Always check your `package.json`: Before uninstalling, it's good practice to review your `package.json` to understand which packages are listed as dependencies.
- Use `npm prune`: After uninstalling packages manually or if your `package.json` becomes out of sync with your `node_modules` folder, you can run `npm prune` to remove any extraneous packages from `node_modules` that are not listed in `package.json`.
- Version control: Commit your `package.json` and `package-lock.json` files after uninstalling packages to keep your repository's dependency state accurate.
By following these steps and understanding the commands, you can effectively manage your project's dependencies using `npm uninstall`.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- npm-uninstall | npm DocsCC-BY-NC-4.0
- Folders | npm DocsCC-BY-NC-4.0
- The Magic Behind npm install and package-lock.jsonfair-use
Missing an answer?
Suggest a question and we'll generate an answer for it.