简体   繁体   English

Grunt安装错误:“应与-g一起安装”

[英]Grunt install error/s: “should be installed with -g”

I'm trying to install Grunt on my machine. 我正在尝试在计算机上安装Grunt。 I have read some tutorials and followed the installation docs , but I can't get it working. 我已经阅读了一些教程并遵循了安装文档 ,但是我无法使其正常运行。

The CLI installs ok using this command: CLI使用以下命令安装成功:

sudo npm install -g grunt-cli

When I select a local directory (containing the package.json and Gruntfile) and npm install , I see the following message: 当我选择本地目录(包含package.json和Gruntfile)并使用npm install ,会看到以下消息:

npm WARN prefer global grunt-cli@0.1.9 should be installed with -g

Why is this happening? 为什么会这样呢? I did install with -g - meaning 'globally', I understand. 我确实使用-g进行安装-我知道这意味着“全局”。

After this, it seems that I cannot run grunt, eg: 在这之后,似乎我无法发出咕unt声,例如:

$ grunt
-bash: grunt: command not found
$ grunt --version
-bash: grunt: command not found

How can I fix this? 我怎样才能解决这个问题? What am I missing? 我想念什么?

Here is my full log: 这是我的完整日志:

$ sudo npm install -g grunt-cli
Password:
npm http GET https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
/Users/tonyMac/.node/bin/grunt -> /Users/tonyMac/.node/lib/node_modules/grunt-cli/bin/grunt
grunt-cli@0.1.10 /Users/tonyMac/.node/lib/node_modules/grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.4)
└── findup-sync@0.1.2 (lodash@1.0.1, glob@3.1.21)
Tonys-iMac:~ tonyMac$ cd projects/testingGrunt
Tonys-iMac:testingGrunt tonyMac$ npm install
npm WARN prefer global grunt-cli@0.1.9 should be installed with -g

You shouldn't use sudo to install package. 您不应该使用sudo安装软件包。
If you use sudo something went wrong when you installed node and npm. 如果使用sudo ,则在安装node和npm时会出错。
I see that you use OSX so, trust me, install node with brew packet manager ( http://brew.sh ) and make it handle node and npm for you. 我看到您使用OSX,所以,请相信我,用brew packet manager( http://brew.sh )安装节点,并使其为您处理node和npm。

Remove node first and then just install Brew following the instruction. 首先删除节点,然后按照说明安装Brew。 Then you can just type brew install node and everything works like a charm. 然后,您只需键入brew install node ,一切就可以像brew install node一样工作。

When you install your locale packages npm install , it's possible a package request grunt-cli as a dependency. 当您安装语言环境软件包npm install ,软件包请求grunt-cli是一个依赖项。 Don't worry about it, this warning don't mean it broke anything. 不用担心,此警告并不意味着它损坏了任何东西。

The grunt: command not found mean that the grunt binary is not added to your Path. grunt: command not found将grunt二进制文件添加到您的Path中。 Add it and you'll be fine: https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path 添加它,你会没事的: https : //unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

The path to add should be this one from the output of your terminal: /Users/tonyMac/.node/bin 从终端输出中添加的路径应为以下路径: /Users/tonyMac/.node/bin

In Bash: PATH=$PATH:/Users/tonyMac/.node/bin (if you run it in command line, then add export command before). 在Bash中: PATH=$PATH:/Users/tonyMac/.node/bin (如果您在命令行中运行它,则在前面添加export命令)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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