How can I install the grunt-cli without getting errors?

瘦欲@ 提交于 2019-12-05 05:11:44

All it took was adding 'sudo', since I didn't have permission to install the grunt-cli by default. Once I ran the following command and entered my password, it worked as expected.

sudo npm install -g grunt-cli

Hope this helps someone!

EDIT: The article quoted below is quite old and refers to pre-v0.3 Yikes! Currently, if npm is run with sudo rights it will downgrade to the nobody user before executing commands.

According to the maintainer of npm, installing packages with sudo is considered bad practice because you are allowing that package to have complete control of your system and you can't and SHOULDN'T trust these packages with root access.

http://howtonode.org/introduction-to-npm

Since you should not install using sudo - you will do this before installing packages and no longer will hit permission errors:

sudo chown -R $USER /usr/local

source: https://howtonode.org/introduction-to-npm

I would recommend installing grunt within your project (instead of using the -g option).

For example, to install the Grunt command line tools use:

cd ~/path-to-my-project
npm install grunt-cli --save-dev

If you want to run grunt then you use:

cd ~/path-to-my-project
./node_modules/./bin/grunt

By installing grunt-cli within your project, you'll have full control over which version gets installed and you don't have to rely on inconsistent PATH variables.

I was having this issue as well, and after reading through the output a little closer i realized that my installed version of node.js was not compatible with the current version of grunt-cli.

Updated node.js problem solved.

Naser

The command for installing grunt in your project folder is :

npm install grunt --save-dev
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!