How to Install Gulp.js on Rocky Linux 8

Gulp is a cross-platform free, open-source JavaScript toolkit that helps developers automate and enhance workflows. Gulp is a task running built on Node.js and NPM that helps developers reduce many time-consuming tasks such as modification and optimization, amongst many other things. Gulp also features a piping output from one task as an input into the next.

In the following tutorial, you will learn how to install Gulp.js on Rocky Linux 8.

Prerequisites

  • Recommended OS: Rocky Linux 8.+.
  • User account: A user account with sudo or root access.
  • Required Packages: curl, node and npm

Update Operating System

Update your Rocky Linux operating system to make sure all existing packages are up to date:

sudo dnf upgrade --refresh -y

The tutorial will be using the sudo command and assuming you have sudo status. To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@rockylinux ~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on How to Add a User to Sudoers on Rocky Linux.

To use the root account, use the following command with the root password to log in.

su

Check or Install Curl Package

Curl is needed for some parts of this guide. To install this package, type the following command:

sudo dnf install curl -y

Install Node.js

To successfully install and, more importantly, use Gulp.js, you need to install Node.js. The process is relatively easy.

First, you will need to import the Node.js (Latest Version 16) source with the curl command as follows:

sudo curl -fsSL https://rpm.nodesource.com/setup_current.x | sudo bash -

Note, alternative versions can be found on the Node source release page.

Next, type the following command to install the Node.js package:

sudo dnf install nodejs

Example output:

How to Install Gulp.js on Rocky Linux 8

Type “Y,” then press the “ENTER KEY” to proceed with the installation.

During the installation, you will be prompted to import the GPG key:

How to Install Gulp.js on Rocky Linux 8

You need to accept this, or the installation will fail; TYPE Y, then press the ENTER KEY to confirm and complete the installation.

To confirm Node.js was installed successfully and to ensure the build and version, use the following:

node -v

Example output:

v.16.8.0

When you installed Node.js, it automatically installed NPM as well. To verify the version and build, you can also use the following command:

npm -v

Example output:

7.21.0

Install Gulp.js on Rocky Linux 8

Install Gulp CLI

The first step is to install the Gulp CLI tool globally on your Rocky Linux system, which is used to work with and manage your Gulp.js application.

To install the Gulp CLI tool, execute the following command:

npm install -g gulp-cli

Once installed, move on to installing Gulp.js.

Install Gulp.js

To install Gulp.js, you need first to create a directory used as your application directory.

Use the following command as an example:

sudo mkdir gulp-directory && cd gulp-directory

Now that you created the directory and have navigated to it, create a new application with the following npm command:

sudo npm init

Next, you will see a series of questions to provide information on your new application, as shown below:

package name: (gulp-directory) 
version: (1.0.0) 
description: Gulp Application
entry point: (index.js) 
test command: echo "My app" $$ exit 1
git repository: 
keywords: gulp
author: Joshua James
license: (ISC) 
About to write to /home/joshua/gulp-directory/package.json:

{
  "name": "gulp-directory",
  "version": "1.0.0",
  "description": "Gulp Application",
  "main": "index.js",
  "scripts": {
    "test": "echo \"My app\" $$ exit 1"
  },
  "keywords": [
    "gulp"
  ],
  "author": "Joshua James",
  "license": "ISC"
}


Is this OK? (yes) yes

Once complete, install the Gulp module to your application with the following terminal command:

sudo npm install --save-dev gulp

To confirm Gulp.js was installed successfully and to ensure the build and version, use the following:

gulp --version

Example output:

CLI version: 2.3.0
Local version: 4.0.2

Create an Test Application (Hello World Example)

Now that you have successfully installed Gulp.js in your application directory, you will create a quick example to get familiar with how to use Gulp.js by creating the famous Hello World quick application example.

First, navigate to your directory and create the gulpfile.js file:

cd gulp-direct && sudo nano gulpfile.js

Now copy and paste the following code:

var gulp = require('gulp');

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

Save the file (CTRL+O), then exit (CTRL+X).

Next, run the Gulp task by executing the following command:

gulp hello

Example output:

[22:49:40] Using gulpfile /home/joshua/gulp-directory/gulpfile.js
[22:49:40] Starting 'hello'...
Hello World!!!
[22:49:40] Finished 'hello' after 1.21 ms

Comments and Conclusion

You have learned how to install Gulp.js on your Rocky Linux 8 system and make a quick test application in the tutorial. Gulp is fantastic as it lets the user automate processes and run repetitive tasks with ease and is highly popular amongst many developers.

For further information, visit the official documentation page for further learning.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!