问题描述
我试图在我的机器上安装Grunt。我已阅读了一些并遵循,但我无法正常工作。
I'm trying to install Grunt on my machine. I have read some tutorials and followed the installation docs, but I can't get it working.
使用此命令,CLI安装正常:
The CLI installs ok using this command:
sudo npm install -g grunt-cli
当我选择一个本地目录(包含package.json和Gruntfile)和 npm install
,我看到以下消息:
When I select a local directory (containing the package.json and Gruntfile) and npm install
, I see the following message:
npm WARN prefer global [email protected] should be installed with -g
为什么会发生这种情况?我确实安装了 -g
- 意思是'全球',我明白了。
Why is this happening? I did install with -g
- meaning 'globally', I understand.
之后,似乎我不能运行grunt,例如:
After this, it seems that I cannot run grunt, eg:
$ 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
[email protected] /Users/tonyMac/.node/lib/node_modules/grunt-cli
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])
Tonys-iMac:~ tonyMac$ cd projects/testingGrunt
Tonys-iMac:testingGrunt tonyMac$ npm install
npm WARN prefer global [email protected] should be installed with -g
推荐答案
您不应该使用 sudo
来安装软件包。
如果你使用 sudo
当你安装了node和npm时出了点问题。
我看到您使用OSX,请相信我,使用brew数据包管理器安装节点( http:// brew。
You shouldn't use sudo
to install package.
If you use sudo
something went wrong when you installed node and 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.
先删除节点,然后按照说明安装Brew。
然后你可以输入 brew install node
,一切都像魅力一样。
Remove node first and then just install Brew following the instruction.Then you can just type brew install node
and everything works like a charm.
这篇关于Grunt安装错误/ s:“应与-g”一起安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!