2013-11-04 37 views
2

我正在尝试在我的机器上安装Grunt。我已阅读tutorials并遵循installation docs,但我无法正常工作。Grunt安装错误/ s:“应该用-g安装”

的CLI安装确定使用该命令:

sudo npm install -g grunt-cli 

当我选择的本地目录(包含的package.json和Gruntfile)和npm install,我看到下面的消息:

npm WARN prefer global [email protected] 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 
[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 

回答

1

当您安装的语言环境软件包npm install,这是可能的一个包请求grunt-cli作为一个依赖。不要担心,这个警告并不意味着它破坏了任何东西。

grunt: command not found意味着grunt二进制文件未添加到您的路径中。添加它,你会被罚款: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命令之前)。

+0

谢谢西蒙 - 那么这个命令是否正确? 'export PATH =〜/ opt/bin:$/Users/tonyMac/.node/bin' –

+0

不应该有'$' –

+0

(选择一个项目文件夹),我运行了那个然后'npm install'。这会返回'-bash:npm:command not found'。我不明白什么是错的? –

2

您不应该使用sudo来安装软件包。
如果您使用sudo安装节点和npm时出现问题。
我看到您使用OSX,请相信我,使用brew数据包管理器(http://brew.sh)安装节点,并使其为您处理节点和npm。

先删除节点,然后按照说明安装Brew。 然后你可以输入brew install node,一切都像魅力一样。

+0

谢谢oozic!我删除了节点并重新安装了brew(好东西!)。我试过再次运行grunt,但不幸的是我得到了一些错误:'ERR!错误:EACCES,取消链接和以管理员身份运行命令。这听起来正确吗?我可以提供更多的代码。 –

+0

那么,你的机器是否使用管理员帐户,或者你的帐户有一些限制? – mtt

+0

我有管理权限,这是唯一的用户帐户。也许对某个文件/目录有读/写限制? –