我正在尝试在我的机器上安装Grunt。我已阅读了一些tutorials并遵循了installation docs,但我无法让它发挥作用。
使用以下命令安装CLI:
sudo npm install -g grunt-cli
当我选择本地目录(包含package.json和Gruntfile)和npm install
时,我看到以下消息:
npm WARN prefer global grunt-cli@0.1.9 should be installed with -g
为什么会这样?我确实安装了-g
- 意思是“全局”,我理解。
在此之后,似乎我无法运行咕噜声,例如:
$ grunt
-bash: grunt: command not found
$ grunt --version
-bash: grunt: command not found
我该如何解决这个问题?我错过了什么?
这是我的完整日志:
$ 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
答案 0 :(得分:2)
您不应使用sudo
来安装软件包。
如果在安装node和npm时使用sudo
出错了。
我看到你使用OSX,相信我,使用brew数据包管理器(http://brew.sh)安装节点并让它为你处理节点和npm。
首先删除节点,然后按照说明安装Brew。
然后你可以输入brew install node
,一切都像魅力一样。
答案 1 :(得分:1)
安装区域设置包npm install
时,包请求grunt-cli
可能是依赖项。不要担心,这个警告并不意味着它破坏了任何东西。
grunt: command not found
表示grunt二进制文件未添加到Path中。添加它就可以了:https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path
要添加的路径应该来自终端的输出:/Users/tonyMac/.node/bin
在Bash中:PATH=$PATH:/Users/tonyMac/.node/bin
(如果你在命令行中运行它,那么在之前添加export
命令。)