Grunt Shell – Run Shell Command Through Grunt Task

Grunt is a great way to automate our development processes. Sometimes we have to rely on some packages either they are NPM package or they are Bower components. It’s not necessary if our client’s production server have all those packages installed already or they don’t give access to set up the environment or install missing dependencies.

It’s not only limited to missing packages, maybe we want to do something with shell, for example, install those packages to separate directory or let’s say just want to create a directory for any reason!

Grunt shell is here to help us in this regard.

Install Grunt

First of all, you need to install Grunt, in your development environment of course, from Node Package Manager. I’m using VS Code, it has a very handy integrated terminal. Press Ctrl + ` to open up the terminal and install Grunt by pasting the following commands.

npm install grunt

Install Grunt Shell

After the successful installation of Grunt, now install Grunt Shell by running the following command.

npm install grunt-shell

Write Grunt Task

Create a file in your project root directory with the name “Gruntfile.js” and define the Grunt Task in it to run shell commands.



module.exports = function(grunt) {
    shell: {
            command: [
                 "npm install bower",
                 "bower install angular",
                 "bower install angularjs",
                 "bower install bootstrap",
                 "bower install jquery",
                 "bower install tether"

  grunt.registerTask('default', ['shell']);


Now run Grunt task by typing “Grunt” in the terminal, as it is registered as default task, that’s why there is no need to mention the name of the task.

All the shell commands mentioned in the task has started executing.

Ahmed Khateeb

Computer Scientist, Former intern at Microsoft, Developer and Blogger. "Tech Enthusiast".

Leave a Reply

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