How to Uninstall Packages with npm or Yarn

Two of the most popular package managers are npm and Yarn.

Here's a short guide on uninstalling/remove packages with npm or Yarn so you can keep your package.json clean. 🧽

A conveyor belt processing packages

Uninstalling Packages with NPM:

Uninstalling packages using NPM is straightforward. You can uninstall a package locally or globally using the following commands:

Local uninstallation

To uninstall a package locally, navigate to your project's root directory and run the following command:

npm uninstall <package-name>

For example, to uninstall the "lodash" package:

npm uninstall lodash

Global Uninstallation

To uninstall a package globally, you need to add the -g flag to the command:

npm uninstall -g <package-name>

Uninstalling Packages with Yarn

Uninstalling packages using Yarn is also easy. You can uninstall a package locally or globally using these commands:

Local uninstallation

To uninstall a package locally with Yarn, navigate to your project's root directory and run the following command:

yarn remove <package-name>

For example, to uninstall the "lodash" package:

yarn remove lodash

Global Uninstallation

Yarn uses a different command for global uninstallation. After identifying the package you want to remove, use the following command to uninstall it:

yarn global remove <package-name>

I hope this helped! 🚀

Follow me on Twitter or connect on LinkedIn.

YarnHow ToNpmJavaScript
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses: Lead Developer, Software Architect, Product Manager, CTO, and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.