2013-11-04 35 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

我有管理權限,這是唯一的用戶帳戶。也許對某個文件/目錄有讀/寫限制? –