Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm package.json install globally?

Tags:

node.js

npm

Is there any way to set an NPM dependency to be installed globally in the package.json file?

Whenever I run npm update all the dependencies are installed locally.

Thanks.

like image 477
Mark Avatar asked May 12 '11 22:05

Mark


2 Answers

I believe that the -g option causes things to be installed globally.

like image 165
nicolaskruchten Avatar answered Oct 04 '22 02:10

nicolaskruchten


Is your reason for installing globally in order to make new scripts available on the command line? If so, I might have a workaround for you.

Just install your packages as usual (without the -g):

npm install -S my_module_name

Including the -S flag or --save will help keep your package.json file up to date.

As usual, your project's npm install step will install locally (as you have described). However, it will also produces a local folder containing symlinks to each of the project's npm-supplied command-line executables (located inside the node_modules/.bin/ folder).

Add that folder to your system path to enable command-line access to npm modules without requiring installation via -g, or root access to a machine:

export PATH=/path/to/your/project/source/node_modules/.bin/:$PATH
like image 23
ʀɣαɳĵ Avatar answered Oct 04 '22 01:10

ʀɣαɳĵ