Best Steps to Install Gradle on Ubuntu 20.04


In this article, I will take you through the best steps to install Gradle on Ubuntu 20.04. Gradle is a build automation tool mostly used by DevOps Professional to test, deploy and publish the package. It supports multiple languages like Java, C/C++ and JavaScript. There are multiple ways to Install Gradle tool on Linux Based Systems but here we will focus on the most simplest way.

Best Steps to Install Gradle on Ubuntu 20.04

Best Steps to Install Gradle on Ubuntu 20.04

Also Read: 5 Easy Steps to Install Visual Studio Code on Ubuntu 20.04

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 Server.

b) You should have sudo or root access to run all privileged commands.

c) You should have apt, unzip and wget utility installed in your Server.

Step 2: Update Your Server

Before going through the steps to install Gradle tool, it is always recommended to first update all the installed packages from Ubuntu repo using apt update command as shown below.

root@localhost:~# apt update
Hit:1 focal InRelease
Get:2 focal-updates InRelease [114 kB]
Hit:3 stable InRelease
Get:4 focal InRelease [17.5 kB]
Get:5 focal-security InRelease [114 kB]
Get:6 focal-backports InRelease [101 kB]
Err:4 focal InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4E72F77D7D158F33
Get:7 focal-updates/main amd64 Packages [1,077 kB]
Get:8 focal-updates/main i386 Packages [499 kB]
Get:9 focal-security/main amd64 DEP-11 Metadata [24.5 kB]


Step 3: Install OpenJDK

Then the next step is to install the Java package if it is not already installed in your System. Gradle requires JDK libraries as prerequisites. You can install the default JDK package by using apt install default-jdk command as shown below.



Please note that here I am using root user to run all the below commands. You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.
root@localhost:~# apt install default-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
default-jdk-headless default-jre default-jre-headless
The following NEW packages will be installed:
default-jdk default-jdk-headless default-jre default-jre-headless
0 upgraded, 4 newly installed, 0 to remove and 180 not upgraded.
Need to get 6,512 B of archives.
After this operation, 38.9 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y

After successful installation, you can check the Java version by using java --version command.

root@localhost:~# java --version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)


Step 4: Download Gradle Package 

You can go to Gradle Download page and pull the latest binary release by using wget command as shown below. Below wget command will download the Gradle zip package in current directory. At the time of writing this article, is the latest version available.

root@localhost:~# wget
--2021-06-27 20:05:43--
Resolving ( 2606:4700::6812:a463, 2606:4700::6812:a563,, ...
Connecting to (|2606:4700::6812:a463|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 112062163 (107M) [application/zip]
Saving to: ‘’ 100%[============================================================================>] 106.87M 16.4MB/s in 6.7s

2021-06-27 20:05:50 (15.9 MB/s) - ‘’ saved [112062163/112062163]

Then check the downloaded package by using ls -lrt command as shown below.

root@localhost:~# ls -lrt
-rw-r--r-- 1 root root 112062163 May 14 17:42


Step 5: Extract Gradle Package

You can extract Gradle zip package to any of the directory path you want. We will setup our Gradle package under /usr/local directory. Before that we will create a directory called Gradle and will extract zip package under this directory using unzip command as shown below.

root@localhost:~# mkdir /usr/local/gradle; unzip -d /usr/local/gradle
creating: /usr/local/gradle/gradle-7.0.2/
inflating: /usr/local/gradle/gradle-7.0.2/LICENSE
inflating: /usr/local/gradle/gradle-7.0.2/NOTICE
inflating: /usr/local/gradle/gradle-7.0.2/README
creating: /usr/local/gradle/gradle-7.0.2/init.d/
inflating: /usr/local/gradle/gradle-7.0.2/init.d/readme.txt
creating: /usr/local/gradle/gradle-7.0.2/bin/
inflating: /usr/local/gradle/gradle-7.0.2/bin/gradle
inflating: /usr/local/gradle/gradle-7.0.2/bin/gradle.bat
creating: /usr/local/gradle/gradle-7.0.2/lib/

If you now check the extracted files using ls -lrt /usr/local/gradle/gradle-7.0.2/ command then it should show under directory /usr/local/gradle as displayed below.

root@localhost:~# ls -lrt /usr/local/gradle/gradle-7.0.2/
total 52
-rw-r--r-- 1 root root 976 Feb 1 1980 README
-rw-r--r-- 1 root root 803 Feb 1 1980 NOTICE
-rw-r--r-- 1 root root 23606 Feb 1 1980 LICENSE
drwxr-xr-x 3 root root 12288 Feb 1 1980 lib
drwxr-xr-x 2 root root 4096 Feb 1 1980 init.d
drwxr-xr-x 2 root root 4096 Feb 1 1980 bin


Step 6: Setup Environment Variables

Now you need to set $PATH environment variable to detect the Gradle binary path. This can be easily done by creating a simple script which will set and export $PATH environment variable.

root@localhost:~# vi /etc/profile.d/
export PATH=$PATH:/usr/local/gradle/gradle-7.0.2/bin

After setting up the script, you can now source it to current terminal session using source /etc/profile.d/ command as displayed below.

root@localhost:~# source /etc/profile.d/


Step 7: Test the Setup

Now that Gradle has been setup successfully, you can go ahead and verify the setup by using gradle -v command as displayed below.

root@localhost:~# gradle -v

Welcome to Gradle 7.0.2!

Here are the highlights of this release:
- File system watching enabled by default
- Support for running with and building Java 16 projects
- Native support for Apple Silicon processors
- Dependency catalog feature preview

For more details see

Gradle 7.0.2

Build time: 2021-05-14 12:02:31 UTC
Revision: 1ef1b260d39daacbf9357f9d8594a8a743e2152e

Kotlin: 1.4.31
Groovy: 3.0.7
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.11 (Ubuntu 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OS: Linux 5.8.0-55-generic amd64


Step 8: Uninstall Gradle

Since we installed Gradle through binary package so to uninstall we just need to delete the packages by using rm -rf /usr/local/gradle/gradle-7.0.2/  command as shown below.

root@localhost:~# rm -rf /usr/local/gradle/gradle-7.0.2/

Then remove script using rm -rf /etc/profile.d/ command as shown below. This will completely remove the Gradle package from System.

root@localhost:~# rm -rf /etc/profile.d/

Leave a Comment