In order to make use of a Grunt configuration file, the Grunt command-line interface (CLI) tool needs to be installed.
Command-line tools such as the Grunt CLI are usually installed globally. This means that they are installed on top of the Node.js installation that is currently active in your terminal, and not in the current project path, as is usually the case.
Tip
In this book, we'll work with version 0.4.x of Grunt, which requires Node.js version 0.8.x or higher.
The following steps will take us through installing the Grunt CLI and testing for its successful installation.
Assuming that you already have a global installation of Node.js, the following is the command to install the Grunt CLI:
$ npm install --global grunt-cli
If the installation was successful, the
grunt
command should now be available on the terminal. Test this by typinggrunt
in your terminal and confirm that it returns a message similar to the following:grunt-cli: The grunt command line interface. (v0.1.13) Fatal error: Unable to find local grunt. If you're seeing this message, either a Gruntfile wasn't found or grunt hasn't been installed locally to your project. For more information about installing and configuring grunt, please see the Getting Started guide: http://gruntjs.com/getting-started
The npm install
command looks up the grunt-cli
package on npm's public package registry, and proceeds to download and install it once it is found.
Using the -g
argument along with the install
command indicates that the package we'd like to install, should be installed globally, meaning it should be installed on the version of Node.js that is currently active in our terminal.
In a default Node.js setup, a folder for executable binaries will automatically be added as a path that should be scanned by the terminal for executable commands. This makes the grunt
command automatically available after the installation of this package, as its executable binary is provided and indicated in the package's installation information.