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 like minification, compilation, unit testing, linting and more; with minimum effort.
Installation
Refresh your local package index:
apt-get update
Install curl
:
apt-get install curl
Add the package repository of NodeJS 8.x with the following command:
curl -sL https://deb.nodesource.com/setup_12.x | bash -
Next, we need to install NodeJS and NPM all together along with the development tools:
apt install build-essential nodejs
Now check to ensure NodeJS and NPM are working:
node --version && npm --version
Install Grunt:
npm install -g grunt-cli
This will install Grunt globally on your system. Run the following command to check the version installed on your system:
grunt --version
Install Grunt on a new project
To install grunt on a new project we will need to add two files 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.jsor
Gruntfile.coffee` and is used to configure or define tasks, as well as to load Grunt plugins.
Navigate to the root directory of your package:
cd /path/to/project
Run the following command to create a package.json
file:
npm init
Answer the questions in the command line questionnaire.
Once your package.json
file is created, install Grunt as a development dependency:
npm install grunt --save-dev
Create the Gruntfile.js
file:
nano Gruntfile.js
Register a simple default task:
var grunt = require('grunt');
grunt.registerTask('default', 'default task description', function(){
console.log('hello world');
});
Now, run the default task:
grunt
That concludes our tutorial, thank you for reading.