Tutorials  /  JavaScript

How to Install and Configure GulpJS on Ubuntu for JavaScript Automation

Ccentron Redaktion · May 2025 ·4 min read ·JavaScript, Tutorial

GulpJS serves as a toolkit designed to automate tedious and repetitive tasks within your development workflow. This tool is capable of automating processes such as minification, obscuration, compiling, and much more.

Essential Requirements

Begin by configuring a non-root user with sudo privileges. Refer to the provided guide for detailed instructions.

Install build-essential Package

Console
$ sudo apt-get install build-essential

Install curl Utility

Console
$ sudo apt-get install curl
VM

Matching infrastructure at centron

Node applications need somewhere to run: ccloud³ VMs with full root access from €3.11 per month – or as a managed server if you would rather not run it yourself. Rent a cloud server →

Installation Steps

Installing NodeJS and NPM

Update and upgrade the current packages on your local system.

Console
$ sudo apt-get update
$ sudo apt-get upgrade

Install the most recent stable release of NodeJS.

Console
$ curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
$ sudo apt-get install -y nodejs

Confirm the successful installation of NodeJS and NPM.

Console
$ node -v && npm -v
v13.11.0
6.13.7

Installing GulpJS CLI

Install the GulpJS Command Line Interface globally.

Console
$ sudo npm install -g gulp-cli

Verify the CLI installation.

Console
$ gulp -v
CLI version: 2.2.0

Configuration and Setup

To utilize GulpJS alongside plugins, you must create a gulpfile.js and a package.json.

  • gulpfile.js: manages configuration, piping, task execution, and plugin management.
  • package.json: tracks project dependencies and their versions.

Navigate to Your Project Directory

Console
$ cd /path/to/project/

Initialize an NPM Project

Create a package.json by running:

Console
$ npm init

When asked for the package name, input gulpjs. Press Enter to accept all default values. You will then receive a summary:

About to write to /root/package.json: { "name": "gulpjs", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" } Is this OK? (yes)

Type yes and hit Enter.

Install Gulp and gulp-uglify Plugin Locally

Console
npm install --save-dev gulp gulp-uglify

Creating a GulpJS Task

Create gulpfile.js

Create a gulpfile.js at the root of your project directory.

Code
nano gulpfile.js

Define the Example Task

Import the required libraries and define a task called exampleTask.

JavaScript
const gulp = require('gulp'); // Import Gulp
const uglify = require('gulp-uglify'); // Import Gulp-Uglify for JavaScript minification

gulp.task('exampleTask', () => {
    return gulp.src('/path/to/javascript/files/*.js') // Source JavaScript files
        .pipe(uglify()) // Minify the files
        .pipe(gulp.dest('/path/to/destination/')); // Output to destination
});

Verify the JavaScript Files

Ensure that there is at least one JavaScript file available at the specified source path.

Console
$ ls /path/to/javascript/files/
file.js

Execute the Gulp Task

Run the newly created task.

Console
$ gulp exampleTask
Working directory changed to ~
Using gulpfile ~/gulpfile.js
Starting 'exampleTask'...
Finished 'exampleTask' after 59 ms

Check the Output Directory

Confirm that the destination folder contains the minified file.

Console
$ ls /path/to/destination/
file.js

Additional Resources

For deeper insights about gulp-uglify, visit https://www.npmjs.com/package/gulp-uglify.

Conclusion

By following this guide, you have successfully installed and configured GulpJS in your development environment. GulpJS streamlines your workflow by automating repetitive tasks like JavaScript minification, making your projects more efficient and maintainable. With the ability to define custom tasks and integrate powerful plugins such as gulp-uglify, GulpJS becomes an essential tool for modern web development. Continue exploring Gulp’s extensive ecosystem to further optimize and enhance your project pipelines.

Claim €200 credit

Test your setup on ccloud³

Sign up for ccloud³ and receive €200 starting credit for your project.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie JavaScript
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Get started for free

Sign up and receive €200 credit at centron within your first 60 days.

This promotional offer applies to new accounts only. Available exclusively to businesses.