Installing Grunt on OS X and Windows 7

zigzag

Am I available?

Maybe, who knows?
I should, so get in touch over at Contact .

Coming primarily from a PC-based development background, I thought it might be useful to provide a step by step guide to installing Grunt on a Mac as well as a Windows 7 PC.

Firstly, Grunt (currently v0.4.0 at the time of writing) is a JavaScript-based task runner; it allows for the automation of repetitive coding tasks allowing you to spend more time on the parts of your project that needs it, or to give Grunt’s own definition:

The less work you have to do when performing repetitive tasks like minification, compilation, unit testing, linting, etc, the easier your job becomes.

which sounds pretty great to me.

Jump to

Installing Grunt for Mac OS X

Firstly, you’ll need to install the Node.js package manager.

Hopefully this will be done automatically for you using the installer (.pkg) that can be downloaded from the Node website, but if you’re having problems, you might be able to install a different way.

Open Terminal, and make sure the Node package manager is installed by typing ‘npm’ and hitting enter, i.e.

Macbook-Name:~ yournamehere$ npm

If installed correctly, it will give you a list of information such as:

Usage: npm < command>

If Terminal is not recognising the ‘npm’ command, you’ll need to try to install in again, perhaps using a different method.

Now, to install Grunt, you’ll need the Grunt CLI (Command Line Interface). In case you’ve installed Grunt before and forgot about it (it happens) it’s recommend that you remove it and start afresh for our purposes. In Terminal, type:

npm uninstall -g grunt

For me, as Grunt was not installed, I received the message:

npm WARN uninstall not installed in /usr/local/lib/node_modules: "grunt"

I then needed to install Grunt CLI globally by typing:

npm install -g grunt-cli

For me this gave me the error code: EACCES, which is seemingly a permission error, so instead I tried:

sudo npm install -g grunt-cli

Which installed the Grunt CLI successfully.

Note, that this only installs the Grunt CLI (not the Grunt task runner). The idea for this is that the Grunt CLI will look for the custom version of Grunt and the Grunt plugins for each project using the Gruntfile provided in the root directory of your project. For more information on setting up a new Grunt project or working with an existing Grunt project, see the official Grunt getting started guide here.

Installing Grunt for Windows 7

Firstly, you’ll need to install the Node.js package manager.

Hopefully this will be done automatically for you using the installer (.msi) that can be downloaded from the Node website, but if you’re having problems, you might be able to install a different way.

Open Command Prompt (to do this you can go to Start and type cmd.exe) and make sure the Node package manager is installed by typing ‘npm’ and hitting enter, i.e.

C:UsersYourName> npm

If installed correctly, it will give you a list of information such as:

Usage: npm < command>

If Command Prompt is not recognising the ‘npm’ command, you’ll need to try to install in again, perhaps using a different method.

Now, to install Grunt, you’ll need to install Grunt CLI (Command Line Interface). In case you’ve installed Grunt before and forgot about it (it happens) it’s recommend that you remove it and start afresh for our purposes. In Terminal, type:

npm uninstall -g grunt

For me, as Grunt was not installed, I received the message:

npm WARN uninstall not installed in C:UsersMyNameAppDataRoamingnpmnode_modules: "grunt"

I then needed to install Grunt CLI globally by typing:

npm install -g grunt-cli

Note, that this only installs the Grunt CLI (not the Grunt task runner). The idea for this is that the Grunt CLI will look for the custom version of Grunt and the Grunt plugins for each project using the Gruntfile provided in the root directory of your project. For more information on setting up a new Grunt project or working with an existing Grunt project, see the official Grunt getting started guide here.

Sources:

Comments

12 responses to “Installing Grunt on OS X and Windows 7

  1. I can run fine on Mac but on Windows7 my grunt install fails (under straight dos-box or cygwin) with Error:UNABLE_TO_VERIFY_LEAF_SIGNATURE

    $ npm uninstall -g grunt
    $ npm uninstall grunt
    $ npm uninstall -g grunt-cli
    npm WARN uninstall not installed in AppDataRoamingnpmnode_modules: “grunt-cli”
    $ npm uninstall grunt-cli
    npm WARN uninstall not installed in C:UsersHalworkspacea2node_modules: “grunt-cli”

    $ npm install -g 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/grunt-cli
    npm ERR! Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE
    npm ERR! at SecurePair. (tls.js:1283:32)
    npm ERR! at SecurePair.EventEmitter.emit (events.js:92:17)
    npm ERR! at SecurePair.maybeInitFinished (tls.js:896:10)
    npm ERR! at CleartextStream.read [as _read] (tls.js:430:15)
    npm ERR! at CleartextStream.Readable.read (_stream_readable.js:304:10)
    npm ERR! at EncryptedStream.write [as _write] (tls.js:344:25)
    npm ERR! at doWrite (_stream_writable.js:211:10)
    npm ERR! at writeOrBuffer (_stream_writable.js:201:5)
    npm ERR! at EncryptedStream.Writable.write (_stream_writable.js:172:11)
    npm ERR! at write (_stream_readable.js:557:24)
    npm ERR! If you need help, you may report this log at:
    npm ERR!
    npm ERR! or email it to:
    npm ERR!

    npm ERR! System Windows_NT 6.1.7601
    npm ERR! command “C:\Program Files (x86)\nodejs\node.exe” “C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js” “install” “-g” “grunt-cli”
    npm ERR! cwd C:UsersHalworkspacea2
    npm ERR! node -v v0.10.5
    npm ERR! npm -v 1.2.18

    Any suggestions? Goggling shows this issue as “closed” but its still here in the current (10.5, 1.2.18) versions. Thanks in advance.

  2. Thank you so much!!!! So many sites assume newbies to theme development get the basic steps- which we don’t. This really helped me with my Roots site development:)

  3. To save Mac users from a bit of head scratching:

    Before trying to run “npm install” on a project, make sure you have agreed to the Xcode license agreement (and obviously installed Xcode, available for free from the App Store). The easiest way to accept the license is to run the GUI version of Xcode for the first time.

    At least that was required for me, installing from the node .pkg file.

    Now time to tinker with ModernMail for (hopefully) easy Bootstrap responsive email layouts.
    If all goes well, I’ll see how much work needs to be done to make a Bootstrap 3 version.

  4. I am trying to install grunt for windows 7, installed node.js successfully
    when i type npm command, it is giving usage info “Usage: npm …”
    when i tried “npm install -g grunt-cli” command it is giving bellow mentioned error. please help me.

    npm ERR! Error: connect ECONNREFUSED
    npm ERR! at errnoException (net.js:904:11)
    npm ERR! at Object.afterConnect [as oncomplete] (net.js:895:19)
    npm ERR! { [Error: connect ECONNREFUSED]
    npm ERR! code: ‘ECONNREFUSED’,
    npm ERR! errno: ‘ECONNREFUSED’,
    npm ERR! syscall: ‘connect’ }
    npm ERR!
    npm ERR! If you are behind a proxy, please make sure that the
    npm ERR! ‘proxy’ config is set properly. See: ‘npm help config’

    npm ERR! System Windows_NT 6.1.7601
    npm ERR! command “C:\Program Files (x86)\nodejs\\node.exe” “C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js” “install” “-g” “grunt-cli”
    npm ERR! cwd C:UsersM1022339
    npm ERR! node -v v0.10.33
    npm ERR! npm -v 1.4.28
    npm ERR! syscall connect
    npm ERR! code ECONNREFUSED
    npm ERR! errno ECONNREFUSED
    npm ERR! stack Error: connect ECONNREFUSED
    npm ERR! stack at errnoException (net.js:904:11)
    npm ERR! stack at Object.afterConnect [as oncomplete] (net.js:895:19)
    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR! C:UsersMyNamenpm-debug.log
    npm ERR! not ok code 0

  5. after node.js is installed on Windows 8 , the entire systemneeds to be rebooted! This is very important to know, as nobody advises todo so. My assumption was that node would be in effect right after the installation. That is not the case. Reboot to apply node!

Leave a Reply

Your email address will not be published. Required fields are marked *

Don't Be Shy