Install package.json dependencies globally

2019-08-10 04:32发布

问题:

There is the following 'package.json' file with dependencies:

{
  "name": "xxx_web_app",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "some.git"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bower": "^1.4.1",
    "connect-history-api-fallback": "^1.1.0",
    "gulp": "^3.8.11",
    "gulp-clean": "^0.3.1",
    "gulp-coffee": "^2.3.1",
    "gulp-connect": "^2.2.0",
    "gulp-jshint": "^1.10.0",
    "gulp-minify-css": "^1.1.1",
    "gulp-sass": "^1.3.3",
    "gulp-slim": "^0.1.0",
    "gulp-uglify": "^1.2.0",
    "gulp-util": "^3.0.4",
    "gulp-webserver": "^0.9.0"
  }
}

When I run 'npm install -g' I see in console that all my dependencies will be installed. But when I try to execute, for example, gulp ('gulp -v') I got:

"zsh: command not found: gulp"

But if I execute 'npm install -g gulp' the thing will work good. So, how can I install all dependencies from my package.json globally without installing one after one? Thanks in advance!

My system is OS X Yosemite.

回答1:

npm install -g or npm install --global when executed within a directory that contains the package.json file will install all the packages as a global package.

Use npm ls -g to check exactly where these packages are installed. Add the path that the above command gives to your appropriate shell. Looks like you are using a zsh.

These steps should work:

cd into your home directory and find this file .zshrc and look for the line with

export PATH=

and modify it like:

export PATH="path_to_global_packages:$PATH"

Open a new tab on your terminal for the changes to take effect and try running gulp -v

Note: One best practice is to install packages locally for each project rather than globally for all projects on a machine.



回答2:

you should add your something to package code I don't remember what to add but you can search fot it (how to upload npm to artifactory, there maybe you will find what you want.