How to uninstall NPM packages

A short tutorial on uninstalling NPM packages from your computer

Posted on August 09, 2021

There are two ways to uninstall NPM packages depending on where you install them:

  • Uninstall local NPM packages
  • Uninstall global NPM packages

This tutorial will help you to do both.

Uninstalling local NPM packages

Local NPM packages are packages that you installed as dependencies to a certain JavaScript project. The local NPM packages are usually installed in the node_modules/ folder created in your project’s root folder.

To uninstall these local packages, you need to run the npm uninstall command from the terminal.

For example, suppose your project has a dependency on vue package as shown in package.json snippet below:

  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^2.6.14",
    "vuex": "^3.6.2"

You can uninstall the package with the following command:

npm uninstall vue

Once the vue package has been removed from the node_modules/ folder, the project dependency on the package will also be removed from the package.json file.

When you want to remove multiple packages, you need to specify the package name separated by a space.

The following command removes both vue and vuex packages:

npm uninstall vue vuex

The same process also applies to packages listed as devDependencies and peerDependencies.

Alternatively, you can also start the uninstallation process by removing the package from package.json file and running the npm install command.

From the above package.json example, just remove the packages listed in the dependencies property:

  "dependencies": {
    "core-js": "^3.6.5",

And then run the npm install command so that the packages will be removed from the node_modules/ folder.

Uninstall global NPM packages

You can uninstall global NPM packages by adding the -g flag to the npm uninstall command.

For example, suppose you have installed the Vue package globally in the past:

npm install -g vue

You can uninstall the package using the following command:

npm uninstall -g vue

And that’s how you can uninstall both local and global NPM packages installed on your computer 😉

Related articles:

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.