## Tutorial ##

How To Install Gradle on Ubuntu 22.04

Published on May 16 2023 · Updated on May 16 2023

In this article, we'll explain about how to install Gradle on Ubuntu 22.04.

Gradle is an open-source build automation tool focused on flexibility and performance. Gradle build scripts are written using a Groovy or Kotlin DSL. Read about Gradle features to learn what is possible with Gradle.

  • Highly customizable — Gradle is modeled in a way that is customizable and extensible in the most fundamental ways.
  • Fast — Gradle completes tasks quickly by reusing outputs from previous executions, processing only inputs that changed, and executing tasks in parallel.
  • Powerful — Gradle is the official build tool for Android, and comes with support for many popular languages and technologies

How to install Gradle on Ubuntu 22.04.


  • A Ubuntu 22.04 installed dedicated server or KVM VPS.
  • A root user access or normal user with sudo privileges.

1. Keep the server up to date

sudo apt update && sudo apt-get upgrade -y

2. Install required package

sudo apt install unzip -y

3. Install OpenJDK

Here, we're installing default OpenJDK 11, which is already included but this will not be the latest version. For Gradle we required OpenJDK 8 and later. 

If your project require latest version or specific version of JDK, please refer official documentation. Execute following command:

sudo apt install default-jdk

Verify the Java installation by printing the Java version :

java -version

4. Download Gradle

At the time of writing this article, the latest version of Gradle is v8.1.1. Before continuing with the next step, you should check the Gradle releases page to see if a newer version is available.

Download the Gradle binary file in the /tmp directory using the following wget command:

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

Once the download is completed, unzip the file in the /opt/gradle directory:

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

5. Configure the environment variables

Next, we'll create one file named gradle.sh to configure the environmental variable PATH. Create a file in the /etc/profile.d directory. Use your favorite editor. For this demonstration purpose, we are using nano editor.

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

Paste the following configuration:

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

Note: Replace gradle-gradle-8.1.1 with the version of your gradle.

Save and exit.

Next, make the script executable by using chmod command like shown below:

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

Load the environment variables using the source command :

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

Above command may not work if you are a normal user with sudo privileges. Please find some way to execute the command or ask you root user to execute this command.

To validate that Gradle is installed properly run the following command which will display the Gradle version:

gradle -v

Output will be similar like:

Welcome to Gradle 8.1.1!

Here are the highlights of this release:
 - Stable configuration cache
 - Experimental Kotlin DSL assignment syntax
 - Building with Java 20

For more details see https://docs.gradle.org/8.1.1/release-notes.html

Gradle 8.1.1

Build time:   2023-04-21 12:31:26 UTC
Revision:     1cf537a851c635c364a4214885f8b9798051175b

Kotlin:       1.8.10
Groovy:       3.0.15
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: (Ubuntu
OS:           Linux 5.15.0-25-generic amd64

That’s it. The installation has been completed successfully.

In this tutorial, we have seen how to install Gradle on Ubuntu 22.04.


Related Tutorials

How To Install Maven on Ubuntu 22.04 - HostnExtra

We'll explain how to install Maven on Ubuntu 22.04. For this demonstration purpose, we're installing current LTS version JDK 17.

How To Install Elasticsearch on Rocky Linux 9 - HostnExtra

We'll explain you how to install Elasticsearch on Rocky Linux 9. We'll perform CRUD operation using RESTful API. It's a distributed, RESTful and analytics.

How To Install Elasticsearch on AlmaLinux 9 - HostnExtra

We'll explain you how to install Elasticsearch on AlmaLinux 9. We'll perform CRUD operation using RESTful API. It's a distributed, RESTful search and analytics.