📜  npm -g (1)

📅  最后修改于: 2023-12-03 15:33:12.526000             🧑  作者: Mango

npm -g

Introduction

npm -g is a command-line interface (CLI) for managing packages and dependencies in Node.js. The -g flag indicates that the package will be installed globally on your system.

By installing packages globally, you can easily access their executables from anywhere on your system. This can be particularly useful for command-line tools and utilities.

Installing Packages

To install a package globally using npm, simply run:

npm install -g <package-name>

For example, to install the express package globally, run:

npm install -g express

Note that you may need administrative privileges to install packages globally. If you're running on a Unix-based system (such as Linux or macOS), you can use sudo to run the command as an administrator. For example:

sudo npm install -g <package-name>
Updating Packages

To update a package that was installed globally, run:

npm update -g <package-name>

For example:

npm update -g express
Listing Installed Packages

To list all packages that were installed globally, run:

npm list -g --depth 0
Conclusion

npm -g is a powerful tool for managing packages and dependencies in Node.js. By installing packages globally, you can easily access their executables from anywhere on your system. Whether you're a beginner or an experienced developer, knowing how to use npm -g is an essential skill for any Node.js programmer.