Global Installation
When you install a package globally, it is placed in a system-wide directory and made available from any location on your system. This is useful for installing tools and utilities that you want to use across multiple projects.
How to Install Globally
To install a package globally, use the -g
or --global
flag:
npm install -g <package-name>
For example, to install the nodemon
package globally, you would run:
npm install -g express
To List all the Global Packages in the system
npm list -g --depth 0
Output:
Location of Installed Packages
The location of globally installed packages depends on your operating system and npm
configuration:
- Windows: Packages are installed in
%APPDATA%\npm\node_modules
. - macOS and Linux: Packages are typically installed in
/usr/local/lib/node_modules
or a user-specific directory like~/.npm-global
.
You can find the exact location by running:
npm root -g
Benefits of Global Installation
- Accessible Everywhere: Packages are available system-wide and can be used in any project.
- Convenient for CLI Tools: Ideal for installing command-line tools that you use frequently.
Where does NPM Install the packages ?
npm
is the default package manager for Node.js, and it is used to install, manage, and distribute JavaScript packages. When you install a package using npm
, it can be installed either locally or globally. The location where npm
installs the package depends on the installation method you use.
Table of Content
- Local Installation
- Global Installation
- Common Issues and Solutions
- Conclusion