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.

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

$ sudo apt update

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

The updates will begin like this:

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

$ sudo apt install openjdk-11-jdk

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

$ java -version

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

You will see the java version in the output.

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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}

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

To load the environment variables in your shell session use:

$ source etc/profile.d/gradle.sh

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

Your output will look like this:

How to Install Gradle Build-Tool on Ubuntu 20.04 linux shell ubuntu

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.