Site icon DesignLinux

How to Install Gulp.js on Ubuntu 20.04

How to Install Gulp.js on Ubuntu 20.04

Gulp.js is an open-source toolkit that helps developers automate the tasks in development workflow. Gulp is useful to make automate processes and run repetitive tasks easily. It also includes the feature of piping output to the another command. This tutorial shows you how to install Gulp.js on Ubuntu 20.04 LTS Linux systems.

Prerequisites

You must logged in with root or user with sudo privileges.

Step 1 – Update Packages

First of all, update the installed packages using following command:

sudo apt update -y
sudo apt upgrade -y

Step 2 – Installing Node.js

Now, we need to install Node.js on system. Add the PPA on your Ubuntu and install using the below command list:

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

Verify the installation by typing:

node -v && npm -v
v15.12.0
 7.6.3

Step 3 – Sample Application with NPM

At this stage, you can easily use the Gulp in your existing Node.js applications by installing Gulp package. Here, we will create a sample Node.js application with NPM.

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

You will be promted for required information to initialize a new empty project under current directory. Input all required information and at the end it will show you the inputted information and confirm.

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

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

Is this OK? (yes)

Hit the Enter key to save all the details.

Step 3 – Installing Gulp on Ubuntu

Use the below command install Gulp CLI globally on your Ubuntu system.

npm install -g gulp-cli

Also you need to install gulp package in your application. Go to your application directory and execute the following command:

npm install --save-dev gulp

That’s it. Check the installed version of Gulp CLI and Gulp Module in your application by typing:

gulp --version
CLI version: 2.2.0
Local version: 4.0.2

Step 4 – Gulp Example

At this point, your system have installed gulp-cli and gulp package to your application.

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

Add the following code to the gulp example file.

var gulp = require('gulp');

gulp.task('welcome', function(done) {
  console.log('Welcome!!!');
  done();
});

Save and close your file.

You can run the gulp task by typing:

gulp welcome

The above command will run the gulp task named “welcome”. It will show you the following output on screen.

Using gulpfile ~/gulpfile.js
Starting 'welcome'...
Finished 'welcome' after 42.5 ms

Conclusion

You successfully learned how to install Gulp.js on your Ubuntu 20.04 system. To learn more visit the official documentation page of Gulp.js.

If you have any questions or suggestion, leave a comment below.

Exit mobile version