Gradle is a well-known software build-tool that is mostly used for development in Java, C++, and Swift. By combining all of the best features of Ant and Maven, it brings the best development practices to its users. Instead of using XML language for scripting, Gradle uses Groovy which is an OO language for defining the project.

This article will show you how to install Gradle with a few simple steps on an Ubuntu 20.04 system.

Pre-Requisites

  • Ubuntu 20.04 system preferably
  • User with sudo rights

Installation of OpenJDK

To install Gradle in your computer system, you need to have Java installed on your machine. To do so, open up the terminal window on your machine using the Ctl+Alt+T shortcut. Or you can simply go to the Applications of your system. Then type Terminal keyword in the search bar of your Applications window.

Open Ubuntu Terminal or connect to your system by SSH

Once you have opened up the terminal window, enter these commands to install OpenJDK.

$ sudo apt update

Update package lists

The updates will begin like this:

Downloading package lists from Ubuntu repository servers

Once the apt package is updated, enter the following command to install OpenJDK.

$ sudo apt install openjdk-11-jdk

Install OpenJDK

The system will prompt, type Y to continue the installation process.

Installing OpenJDK - confirm

The next step is to confirm the installation of Java. To do so, let’s check the installed Java version.

$ java -version

Check the installed Java version

You will see the java version in the output.

JDK 11 installed successfully

Download Gradle in Ubuntu 20.04

To know about the available releases, simply visit the Gradle release page. To this date, the latest Gradle version is 6.8.2. This may vary at the time of your download.

$ VERSION=6.8.2

Set Gradle version variable on the shell

Next, we will download Gradle zip file (Binary only) in the /tmp directory. We will use the following wget command:

$ wget https://services.gradle.org/distributions/gradle-${VERSION}-bin.zip -P /tmp

Download Gradle

After this, the download will begin. You will see an output just this one:

Downloading Gradle source

Once the download of Gradle is completed, users need to unzip the file. This newly created unzipped file will be added to the /opt/gradle directory:

$ sudo unzip -d /opt/gradle /tmp/gradle-${VERSION}-bin.zip

Unzip Gradle archive

This way the process of downloading Gradle will be completed.

Setting up the Environment variables for the new Gradle setup

Let’s set up the environment variables for the newly installed Gradle setup by adding Gradle bin directory to PATH environment variables. We will create a new file and then name it gradle.sh and place it in the /etc/profile.d/ directory. To do so, open up the file in nano editor by using:

$ sudo nano /etc/profile.d/gradle.sh

Create Gradle shell script

Once the editor window is opened, you need to type the following in the /etc/profile.d/gradle.sh file.

export GRADLE_HOME=/opt/gradle/latest 
export PATH=${GRADLE_HOME}/bin:${PATH}

Export Gradle home path

Use, the Ctl+O shortcut to make changes in the file.

Let’s make the script executable using:

$ sudo chmod +x /etc/profile.d/gradle.sh

Make script executable

To load the environment variables in your shell session use:

$ source etc/profile.d/gradle.sh

Load the environment variables in your shell session

Verifying the installation

Once you have installed Gradle in your system, let’s verify this installation by checking the Gradle version. Append the following your terminal window to confirm the installation process.

$ gradle -v

Check Gradle version

Your output will look like this:

Welcome to Gradle 6.8

This marks an end to the installation of Gradle in your system.

Conclusion

In this tutorial, we wrapped up the installation method of Gradle on the Ubuntu 20.04 system in detail. To install Gradle, users need to have OpenJDK installed in their systems and then they have to set up the environment variables to make use of this tool. To know more about Gradle, visit their official documentation.

 

How to Install Gradle Build-Tool on Ubuntu 20.04
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn