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 22.04 systems.
Prerequisites
You must logged in with root or user with sudo privileges.
Step 1 – Update Packages
At first you we will update the installed packages using below given command:
sudo apt update -y
sudo apt upgrade -y
Step 2 – Install Dependencies
We need to install build-essential package for ahead installation. Issue the following command:
sudo apt install build-essential -y
Step 3 – Installing Node.js
Now, we will 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_lts.x | sudo -E bash -
sudo apt update
sudo apt install nodejs -y
Verify the installation by typing:
node -v && npm -v
v18.12.1 7.6.3
Step 3 – Sample Application with NPM
At this point, 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
To install Gulp CLI globally use the below command 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.3.0 Local version: 4.0.2
Step 4 – Gulp Example
At this stage, 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 04.6 ms
Conclusion
You successfully learned how to install Gulp.js on your Ubuntu 22.04 system. To learn more visit the official documentation page of Gulp.js.
If you have any questions or suggestion, leave a comment below.