简体   繁体   中英

Install package.json dependencies globally

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.

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.

您应该在软件包代码中添加一些内容,我不记得要添加什么,但是您可以搜索它(如何将npm上传到工件,也许在那里您会找到想要的东西。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM