What exactly does 'npm install -g ' do?

The g in npm install -g is a flag signifying that you want to install that particular npm module system wide (globally). Without the g option, the module would be installed locally inside the current directory called node_modules -try it!

The location of your globally installed packages can vary depending on how you have installed node. Find out where they are installed by typing npm list -g in your command line.

edit: your error might be caused by insufficient privileges in your npm root directory, but it could also be that the version of node you're using is not supported by that library. Check which version of node you need to run crypt3 and make sure your version of node matches that (node -v). If it does not match the required version, you can use a node version manager such as nvm to switch to that version, and try npm install again.


npm install <package> or npm install -g <package> will

  1. Download an npm package you specify with the argument, or inside your package.json file, along with its dependencies (from the npm repository host you define) inside a node_modules folder. (Or use an already existing local copy of it. see shrink-wrapping)

  2. Run the pre-install, install and post-install scripts for itself and each of its dependencies. See Lifecycle Scripts

  3. The -g directive tells npm to install the package in the global shared node_modules folder (usually where node is). This will also allow you to access the module from the command-line, as the bin is symlinked into a PATH folder (usually usr/local/bin). Check this link

In the case of sinopia, they do not have a standard package.json file, they have a package.yaml file. Check the yamp plugin.

If you check their pre-publish script, it contains

prepublish: js-yaml package.yaml > package.json

Which converts their package.yaml into package.json. In their package.json, they have a dependency on the crypt3 package.

In the case of crypt3 (one of sinopia dependencies), check the package.json . It contains

  "scripts": {
    "test": "node test/test.js",
    "install": "node-gyp rebuild"
  },

So, when sinopia is npm installed, it will download and install all if its dependencies as well. When crypt3 is installed, the "node-gyp rebuild" will be run, which is why you are seeing native c / c++ compile outputs in your console.

You can try it yourself by doing

npm install -g node-gyp && node-gyp rebuild

In the console