How to install global packages, update global packages and uninstall global packages
The previous tutorial was about working with package.json, the current tutorial will be a walkthrough on how to install, update and uninstall global packages. As we stated in our tutorial on installing a package locally, there are two options available for you when you want to install a package: it is either you install it locally or you install it globally. The choice on which kind of installation is dependent on how you want to use the package.
- Whenever you want to use a package as a command line tool, you should install it globally. In this way, it will work no matter which directory is current. This is the choice you should use if you were installing grunt, for example.
- Whereas, when you want to depend on the package from your own module, you should install it locally. This is the choice you would normally use if you are using require statements, for example.
You can use the command npm install -g <package>, for install:
npm install -g jshint
How to Update Global Packages
This requires version 2.6.1 or greater.
If you want to update packages, you should type this command on your terminal:
npm update -g <package>
For instance, if you want to update a package called grunt, you would type:
npm update -g grunt
if you want to find out the packages that needs to be updated, type:
npm outdated -g --depth=0
Finally, if you want to update all global packages, you should type:
npm update -g
If you are using a version below 2.6.1
For any npm version that is below 2.6.1, you should run this script:
#!/bin/sh set -e set -x for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f3) do npm -g install "$package" done
to update all outdated global packages.
However, it is recommended that you upgrade to the latest version of npm. You can do this by typing:
npm install npm@latest -g
How to uninstall global packages
For you to uninstall a package all you need to do is to type:
npm uninstall -g <package>
If you want to uninstall a package called jshint, you would type:
npm uninstall -g jshint
There you go we have successfully shown you how to install, update and uninstall a package.
In the next tutorial we will look at how to create Node.js modules and how to publish & update a package.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join