How to Install Gulp.js on Ubuntu 20.04

How to Install Gulp.js on Ubuntu 20.04

Gulp is an open-source JavaScript toolkit developed by by Eric Schoffstall helps developers to automate & enhance there workflow. It is a good command-line task runner for Node.js applications. Gulp let us automate processes and run repetitive tasks with ease. It provides a feature of piping output from one task as an input to the next.

This tutorial describes you to how to install Gulp on Ubuntu 20.04 LTS Linux systems.

Step 1 – Installing Node.js

First of all, you need to install node.js on your system. Use following set of commands to add node.js PPA in your Ubuntu system and install it.

sudo apt install python-software-properties 
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - 
sudo apt install nodejs -y 

Make sure you have successfully installed node.js and NPM on your system

node --version 
npm --version 

install nodejs for Gulp

Step 2 – Create Sample Application with NPM

Gulp can be easily use in your existing Node.js application. You just need to install Gulp package for Node.js in your project. For this tutorial, I am creating a sample Node.js application with NPM.

mkdir gulp-project && cd gulp-project 
npm init 

This command will prompt the required information to initialize a new empty project under the current directory.

Input all the required details for your application. At the end, it will show you the details you input and ask you to confirm.

About to write to /root/gulp-project/package.json:

{
  "name": "gulp-project",
  "version": "1.0.0",
  "description": "First gulp application by Tecadmin",
  "main": "index.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  },
  "keywords": [
    "gulp",
    "app"
  ],
  "author": "TecAdmin",
  "license": "ISC"
}


Is this OK? (yes)

Just press enter to save all details in package.json file.

Step 3 – Installing Gulp on Ubuntu

Once you have an node.js application. Use the following commands to install Gulp CLI globally on your system.

npm install -g gulp-cli 

Also install the gulp package in your application. Swith to your application directory and execute the following command.

npm install --save-dev gulp 

All done, Let’s check the installed version of Gulp CLI on your system and Gulp module in your application with the following command.

gulp --version 

CLI version: 2.2.0
Local version: 4.0.2

You have successfully installed the Gulp CLI tool on your system.

Step 4 – Gulp Hello World Example

As you have gulp package added your application and installed gulp-cli on your system.

Next, create a gulpfile.js under the application root directory.

nano gulpfile.js 

Add a sample code of gulp hello world example program.

var gulp = require('gulp');

gulp.task('hello', function(done) {
  console.log('Hello World!!!');
  done();
});

Save your file and close.

Next run the gulp task with the following command under the application.

gulp hello 

The above command will run the gulp task named “hello”. As per the above example code, you will see the following results on screen.

Gulp hello world example

Conclusion

This tutorial describes you to install Gulp.js on a Ubuntu system. Visit official documentation page for further development details.

The post How to Install Gulp.js on Ubuntu 20.04 appeared first on TecAdmin.

General Articles gulp TecAdmin