How to install Gradle on Ubuntu 20.04?

Overview

Gradle is a build automation tool used primarily for building Java projects, but it can also be used for other languages such as C++, Python, and Kotlin.

It is designed to be highly flexible and customizable, allowing developers to define their build process in a declarative manner using a Groovy-based domain-specific language (DSL) or the Kotlin language.

This tutorial demonstrates how to set up Gradle on Ubuntu 20.04.

Prerequisites

  • Ubuntu 20.04-equipped system

  • A sudo-privileged user account

  • Internet connection

  • Knowledge of CLI

Get Started

Step 1: Update the package index and upgrade the system:

sudo apt update
sudo apt upgrade

When prompted to continue, enter 'y'.

Step 2: Install the Java Development Kit (JDK) using the following command:

sudo apt install default-jdk

When prompted to continue, enter 'y'.

Step 3: Verify that the JDK has been installed by running the following command:

java -version

Step 4: Download the latest Gradle distribution from the official website using the following command:

wget https://services.gradle.org/distributions/gradle-7.2-bin.zip -P /tmp

Step 5: Install unzip package using the following command:

sudo apt install unzip

Step 6: Unzip the downloaded file and move it to the /opt/gradle directory using the following commands:

sudo unzip -d /opt/gradle /tmp/gradle-*.zip
sudo mv /opt/gradle/gradle-* /opt/gradle/latest

Step 7: Set the GRADLE_HOME environment variable by editing the /etc/environment file using the following command:

sudo nano /etc/environment

Add the following line at the end of the file:

GRADLE_HOME=/opt/gradle/latest

Step 8: Add the Gradle binary files to the system PATH by creating a new file in the /etc/profile.d/ directory using the following command:

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

Add the following lines to the file:

export PATH=$PATH:$GRADLE_HOME/bin

Save and close the file.

Step 9: Apply the changes made to the environment variables by running the following command:

source /etc/environment
source /etc/profile.d/gradle.sh

Step 10: Verify that Gradle has been installed by running the following command:

gradle -v

Congratulations! You have successfully installed Gradle on Ubuntu 20.04.

Conclusion

This tutorial demonstrated how to set up Gradle on a system running Ubuntu 20.04. Before you begin building and installing Gradle, make sure you have all the necessary tools accessible.

Last updated