Gulp is a cross-platform, streaming task runner that lets developers automate many development tasks. At a high level, gulp reads files as streams and pipes the streams to different tasks. These tasks are code-based and use plugins. The tasks modify the files, building source files into production files. To get an idea of what gulp can do check the list of gulp recipes on GitHub.
Prerequisites
Before we install Gulp.js we will need a few things first.
- A server running Ubuntu 20.04 or 18.04. I am using a dedicated server from Spin Servers.
- About 10 minutes and a cup of coffee or hot tea. I prefer Vanilla Chai with a dash of whole milk or almond depending on my mood that day.
Step 1 — Upgrade your system
First things first, always update your system before installing any software or making changes. To do this, use this command:
$ sudo apt-get upgrade
Step 2 — Install Node.js
In order to install Gulp, we will need to first install the Node.js repository.
$ curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
Install Node.js:
$ sudo apt-get install -y nodejs
Verify version:
$ node --version
Step 4 — Create a sample application with NPM
Create a new application directory. Replace ‘app name’ with a name of your choosing.
$ mkdir [app name]
Change to the directory you made and create the application.
$ cd [app name]
$ npm init
Afterward, you will be asked some questions about the application.
Step 5 — Install Gulp.js
Install Gulp.js using the Gulp CLI tool.
$ npm install -g gulp-cli
Once the installer prompts you, change the directory path to your application name.
$ cd /root/[app name]
$ npm install --save-dev gulp
Verify Gulp.js version.
$ gulp --version
Step — Create Gulp Application
Now we can create a sample Gulp application. Use the command below to create the file.
$ nano /root/[app name]/gulpfile.js
Add this content to the file:
var gulp = require('gulp');
gulp.task('hello', function(done) {
console.log('Hello World!!!');
done();
});
Save and exit the file.
Run the Gulp task.
$ gulp hello
Your Gulp.js application is now up and running! :)