Skip to content

How to Uninstall npm packages

We typically install an npm package as follows:

npm install <package_name>
Code language: Bash (bash)

But how do we uninstall an npm package?

How to uninstall an npm package

This will uninstall an npm package that was installed in your project.

Just make sure to run the command from the root directory of your project.

npm uninstall <package_name>
Code language: Bash (bash)

This will remove the package from the node_modules directory and will also remove the reference to it from the package.json file.

How to uninstall a devDependency

If you have a package installed in the devDependency section of your package.json, then you can uninstall it as follows:

npm uninstall -D <package_name>
Code language: Bash (bash)

How to uninstall a global npm package

Sometimes we install npm packages globally, so that we can use them as command-line tools, or if we want them accessible to all projects.

This can be achieved as follows:

npm uninstall -g <package_name>
Code language: Bash (bash)

You may also ask these questions

What happens if I uninstall npm?

When you uninstall npm you are removing packages that have previously been installed by the npm install or npm i commands.

How do I uninstall npm alone?

If you would like to uninstall a specific npm package, then run the following command:

npm uninstall <package_name>
Code language: Bash (bash)

How uninstall npm react?

If you would like to uninstall a Remove Create React App:

# npm npm uninstall -g create-react-app # yarn yarn global remove create-react-app
Code language: Bash (bash)

How do I uninstall and reinstall node and npm?

Delete the node and npm folders located there:

# delete node folder rm -rf /usr/local/bin/node # delete npm folder rm -rf /usr/local/bin/npm
Code language: Bash (bash)

Once both folders are deleted, you can reinstall node and npm using the .pkg file for Mac.

See also  Introduction to NPM

If you install Node using Homebrew, then you can use brew command to uninstall it:

# uninstall node and npm brew uninstall node # install it again brew install node
Code language: Bash (bash)

If you are using Linux Ubuntu, then you can remove Node using apt-get as shown below:

# uninstall node for Ubuntu sudo apt-get remove node # install it again sudo apt-get install node
Code language: Bash (bash)

If you don’t want to uninstall node, then you can try to download and install npm directly using the install.sh script from npmjs.com.

Open the terminal and run the following command:

curl -qL https://www.npmjs.com/install.sh | sh
Code language: Bash (bash)

Typically, if you have an existing npm program installed already, the direct install will fail as shown below:

$ curl -qL https://www.npmjs.com/install.sh | sh # ... # fetching: https://registry.npmjs.org/npm/-/npm-8.13.2.tgz # removing existing npm # failed!
Code language: Bash (bash)

Seems npm direct installation won’t work for some reason.

You need to add the sudo command to the sh pipe as shown below:

curl -qL https://www.npmjs.com/install.sh | sudo sh
Code language: Bash (bash)

If you’re using ZSH, you may see the command above suspended like this:

# zsh: suspended (tty input) sudo sh
Code language: Bash (bash)

When that happens, try to download the install.sh script first, then run it using the sudo command as follows:

# download install.sh curl -O https://www.npmjs.com/install.sh # run the script using sudo sudo sh install.sh # after installation complete, remove the script rm install.sh
Code language: Bash (bash)

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x