乐闻世界logo
搜索文章和话题

What does the "- g " flag do in the command "npm install -g < something >"?

1个答案

1

In the command npm install -g <something>, the -g flag represents "global", meaning global mode. When using this flag to install an npm package, the package is installed system-wide, making it available to all projects rather than just within the local node_modules directory of the current project.

This means that the installed package can be invoked from anywhere via the command line. This is typically used for packages that provide command-line tools. For example, if you install a package named create-react-app using the command npm install -g create-react-app, then the create-react-app command can be invoked from any location on your machine to create new React application projects.

Without using the -g flag, i.e., using npm install <something>, the package will only be installed in the node_modules directory of the current project and is only usable within that project. This approach is used for installing project dependencies to ensure that dependency versions across projects can be managed independently and avoid conflicts with global versions.

2024年7月18日 22:30 回复

你的答案