How to Install GruntJS on Debian 9

GruntJS is a JavaScript task runner written on top of NodeJS. It can be used to automate repetitive tasks for your application, such as minifying, compiling, unit testing, linting, and more; from
with minimal effort.

Why use a task launcher?
In a word: automation. The less work you have to do when doing repetitive tasks like minification, compilation, unit testing, linting, etc., the easier your work becomes. Once you’ve configured it with the Gruntfile, the task executor can do most of this chore for you – and your team – with little or no effort. The Grunt ecosystem is huge and growing every day. With literally hundreds of plugins to choose from, you can use Grunt to automate almost anything with minimal effort. If someone else hasn’t created what you need, creating and publishing your own Grunt plugin in npm is a breeze.

How To Install

Before proceeding with the installation, you need to update the local package index. This can be done with the following command:

sudo apt-get update

Then install curl with:

sudo apt-get install curl

Next, add the NodeJS 8.x package repository:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

Then we need to install NodeJS and NPM along with development tools:

sudo apt-get install build-essential nodejs

Now check if NodeJS and NPM are really working on your server:

node --version && npm --version
#5.x.x
#v8.x.x

Then you need to Install Grunt:

sudo npm install -g grunt-cli

Then Ryou can run the command (described below) to check the version installed

grunt --version
#grunt-cli v1.2.0

Install Grunt into a new project

To install grunt you need to add two files. It need to be added to your project directory: package.json and Gruntfile.js.

  • package.json: This file is used by NPM to store meta-data for projects published as NPM modules.
  • Gruntfile.js: This file is named Gruntfile.js or Gruntfile.coffee`and is used to configure or define tasks, as well as to load Grunt plugins.

Change to the root directory of your package:

cd /path/to/project

Then you need to run the special command to create package.json file:

sudo npm init

Next, you will be asked to answer some questions, you need to answer them in the command line questionnaire. After creating the package.json file, install Grunt as a development dependency:

sudo npm install grunt --save-dev

Then you need to create the Gruntfile.js file:

nano Gruntfile.js

Then remains two things. First, you need to register a simple default task:

var grunt = require('grunt');
grunt.registerTask('default', 'default task description', function(){
  console.log('hello world');
});

Second, run the default task:

grunt

That’s all. The procedure to install GruntJS is finished.

Was this article helpful?

Related Articles

Leave A Comment?