Uninstalling npm: Complete Guide to Removal
In the previous tutorial we showed you how the npm-registry works. The tutorial you are about to read is a guide to removing npm from your local environment. Though npm is a great tool, you might have your preferences and wish to try something else.
To uninstall npm, you have to type this command on the command line:
sudo npm uninstall npm -g
This will uninstall npm globally from your local environment hence running npm on the command line will give you this error:
npm is not recognized as an internal or external command.
If the code above fails, you have to go to the npm source code on your local environment and run:
sudo make uninstall
here is a screenshot of mine:
![npm screenshot of mine](https://www.w3resource.com/w3r_images/npm-screenshot-of-mine.png)
More Severe Uninstalling
In most cases, the instructions above will be sufficient. They will remove npm, however, they will leave behind anything that you have installed.
Continue reading if the above command does not work for you, or if you need more drastic measures.
It should be noted that this is only necessary for packages that were installed globally. Typically, your local installs are completely contained within a project's node_modules folder. Once you delete that folder, everything will be gone (unless you have a package install script).
This tutorial assumes that you installed npm and node in the default place. If you have configured node with a different -prefix, or you installed npm with a different prefix setting, then you will have to adjust the paths accordingly, by replacing /usr/local with your install prefix.
If you want to manually remove everything npm-related do this:
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
If there are things that you installed with npm, then your best bet will be to uninstall them with npm first, then install them back when you have a proper install. The command below can help you that is lying around:
ls -laF /usr/local/{lib/node{,/.npm},bin,share/man} | grep npm
Before npm version 0.3, npm used shim files for executables and node modules. If you want to track these down, you can do the following:
find /usr/local/{lib/node,bin} -exec grep -l npm \{\} \; ;
In this tutorial we have shown you how to remove npm. We have walked you from the basic to more drastic setup. If you complete this and you need to switch back to npm, you have to reinstall it. An alternative to npm is yarn. However, it should be noted that npm and yarn do not miss well in a project.
Thanks for reading. In the next tutorial we will be looking at scopes in npm.
Previous:
Understanding the npm Registry: Features and Functionality.
Next:
Scoped Packages in npm: Complete Guide and Usage.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics