Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

npm

I'm following examples that use the -g flag when using npm install but I can't figure out through the help system what the -g flag is doing.

like image 707
tadasajon Avatar asked Oct 31 '12 21:10

tadasajon


People also ask

What is G flag in npm install?

npm install -g. the -g flag is a shorthand for the global configuration which sets the package install location to the folder where you installed NodeJS. This is useful when you need to run the package from the command line instead of using require() and import it to your code.

What is G in command line?

The G (go) command moves to a specified line and displays it. It can move both backward and forward from the current line. The G command displays one line at a time.

Where does npm install G?

npm install -g pm2 - pm2 will be installed globally. It will then typically be found in /usr/local/lib/node_modules (Use npm root -g to check where.) If you're using nvm, then your global modules may be in one of several places depending on the version of node you're using at the time.

What is G in NodeJS?

js -g parameter installs Node. It can be used within the command line utilities such as npm or commands that come from globally installed modules.


2 Answers

-g tells npm to install the named module so that it's accessible globally.

But it's important to understand that -g is typically only used for packages that provide command-line utilities so that their executable components are available in the system PATH.

If you have multiple programs that require the same package, each program should install the package locally. If you really want to share an installed package by installing it globally, you have to also use npm link.

See the docs on the topic of globally installed packages here.

like image 188
JohnnyHK Avatar answered Oct 14 '22 00:10

JohnnyHK


If you do npm help install you will see that:

  o   npm install (in package directory, no arguments):        Install the dependencies in the local node_modules folder.        In global mode (ie, with -g or --global appended  to  the  com-       mand), it installs the current package context (ie, the current       working directory) as a global package. 
like image 37
K Z Avatar answered Oct 14 '22 00:10

K Z