How to install a global package
There are two ways to install package npm: global and local installation installation. Choose which way to install, depending on how you use this package.
-
If you want it as a command-line tool, then you should install it to the global. After this installation allows you to use this package in any directory . For example grunt should be installed in such a way.
- If you want to rely on your own modules from the package, install it locally. For example, if you are using require statement, you would use this option.
The package is installed to the global, you should use the npm install -g <package>
command, for example: npm install -g jshint
If you encounter EACCES errors, npm Learning (II) of how to prevent permissions error
Tip: If you install npm version 5.2 or later, you can use the global npx run the installation package.
How to update the global installed packages
It requires version 2.6.1 or later. If you are using the older version, please see below.
To update the global package, type: npm Update -g <Package Penalty for>
For example, to update a package called jshint, you need to enter: npm update -g jshint
To find out which packages need to be updated, type:npm outdated -g --depth=0
To update all global package, type: npm Update -g
If you are using version 2.6.0 or below
For less than npm version 2.6.1, run this script to update all outdated global package.
However, please consider upgrading to the latest version of npm. To do this, type: npm install npm@latest -g
.
How to uninstall globally installed package
The package (package) is mounted to a global command by:npm uninstall -g <package>
For example, the global installation package jshint, using the following command: npm uninstall -g jshint