2

I'm new to gruntjs and am trying to get the grunt-init templates up and running however I constantly get this error: zsh: command not found: grunt-init

when I run the install it shows me all of this, so it seems like it is installing fine

→ npm install -g grunt-init
/Users/jsturgess/npm-global/bin/grunt-init -> /Users/jsturgess/npm-global/lib/node_modules/grunt-init/bin/grunt-init
grunt-init@0.3.2 /Users/jsturgess/npm-global/lib/node_modules/grunt-init
├── semver@1.0.14
├── colors@0.6.2
├── async@0.2.10
├── hooker@0.2.3
├── lodash@2.4.1
├── prompt@0.1.12 (async@0.1.22, pkginfo@0.3.0, winston@0.5.11)
└── grunt@0.4.5 (which@1.0.9, dateformat@1.0.2-1.2.3, eventemitter2@0.4.14, getobject@0.1.0, rimraf@2.2.8, async@0.1.22, grunt-legacy-util@0.2.0, exit@0.1.2, nopt@1.0.10, lodash@0.9.2, coffee-script@1.3.3, underscore.string@2.2.1, glob@3.1.21, iconv-lite@0.2.11, grunt-legacy-log@0.1.1, js-yaml@2.0.5, minimatch@0.2.14, findup-sync@0.1.3)

I've followed the grunt-init install directions and made the ~/.grunt-init/ directory and cloned the jquery template via the command the gave

git clone https://github.com/gruntjs/grunt-init-jquery.git ~/.grunt-init/jquery

What do I need to do to be able to use the grunt-init command?

JSturgessMeyers
  • 85
  • 1
  • 2
  • 11

2 Answers2

1

Seems like you are using OhMyZsh. You need to add the Grunt files to your $PATH variable.

cd into your home directory and find this file .zshrc and look for the line with

export PATH=

and modify it like:

export PATH="path_to_grunt:$PATH"

the ':' serves as a delimiter for multiple paths.

What you are probably looking for is here:

export PATH="/usr/local/lib/node_modules/grunt-cli/bin/grunt:$PATH"
sandeep s
  • 385
  • 2
  • 8
  • my $PATH variable starts with $PATH: rather than ending with :$PATH, and most of the paths are ~/. Would that be causing any issues? – JSturgessMeyers Apr 24 '15 at 13:48
  • Yes it does start with $PATH. But, when you say export PATH = 'somethin': $PATH , the 'something' is appended to your existing PATH environment variable. – sandeep s Apr 24 '15 at 13:51
  • As for the path for grunt, it is installed in ~/npm-global/lib/node_modules/grunt and in ~/npm-global/bin there is a grunt alias that links to the one in the lib folder. The lib folder also contains grunt-cli, grunt-init and npm directories. My path variable contains "~/npm-global/bin:~/npm-global/lib/node_modules:" – JSturgessMeyers Apr 24 '15 at 13:52
  • So should I move $PATH to the end, or start with PATH="$PATH:'something':$PATH – JSturgessMeyers Apr 24 '15 at 13:56
  • Can you try this export PATH=~/npm-global/lib/node_modules/grunt-init:$PATH preferably from your home directory – sandeep s Apr 24 '15 at 13:56
  • Am I supposed to just overwrite my path variable with that then try and run something like grunt --version, or should I be running the export PATH in the terminal? – JSturgessMeyers Apr 24 '15 at 14:03
  • On the terminal, cd into your home directory and run this: export PATH=~/npm-global/lib/node_modules/grunt-init:$PATH and then check your .zshrc file if the changes have taken effect. Then try grunt-init or grunt --version – sandeep s Apr 24 '15 at 14:07
  • That did not change anything in my .zshrc file, ran the grunt version anyways and still no grunt command. To add a little more info, grunt no longer even works in the one project I had already set up. Yesterday when I stopped working on that project to start trying things with the grunt-init I followed these [steps](https://docs.npmjs.com/getting-started/fixing-npm-permissions) to change my npm permissions. Would that be the cause of all my problems? – JSturgessMeyers Apr 24 '15 at 14:11
  • No those instructions are perfect for the error you see. She does mention to back-up before starting the process. The answer i posted is present as one of the steps. Since you are using zsh just add export PATH=~/npm-global/lib/node_modules/grunt-init:$PATH to the END of your .zshrc file after all the lines that start with '#' – sandeep s Apr 24 '15 at 14:17
  • I added that at the end of my file and there was no change. My current export PATH has " after the = and at the end of the path, does that line need those as well, and do I need to delete the current export PATH line that is currently present in the middle of the file? – JSturgessMeyers Apr 24 '15 at 14:23
  • My mistake don't delete the existing line. Add this to the end export PATH="~/npm-global/lib/node_modules/grunt-init:$PATH" – sandeep s Apr 24 '15 at 14:29
  • Also, can I leave $PATH: at the beginning as well, because another error gets thrown up (unrelated to grunt) when I don't start the path with that. – JSturgessMeyers Apr 24 '15 at 14:38
  • Can we have this discussion on chat? U need to invite me, i don't have enough reputation for that – sandeep s Apr 24 '15 at 14:42
  • I don't have enough rep to create a room for us to chat in, does email work? – JSturgessMeyers Apr 24 '15 at 14:51
1

Fixed this problem by undoing the npm permission changes I had done from this article: https://docs.npmjs.com/getting-started/fixing-npm-permissions

JSturgessMeyers
  • 85
  • 1
  • 2
  • 11