Set up Gradle on Ubuntu 22.04 – Quick and Efficient Steps

This tutorial intends to teach you to Set up Gradle on Ubuntu 22.04. Gradle is a build automation tool often used for JVM languages such as Java, Groovy, or Scala. Gradle can be configured to run Tasks that do things like compile jars, run tests, create documentation, and much more.

You may be wondering if you need Gradle or a similar build system. Simply put: Whenever a project is slightly more complex than the canonical Hello World print, you need Gradle.

Steps To Set up Gradle on Ubuntu 22.04

To complete this guide, log in to your server as a non-root user with sudo privileges. To do this, follow our guide on the Initial Server Setup with Ubuntu 22.04.

Now follow the steps below to install the latest release of Gradle from their official website.

Install OpenJDK on Ubuntu 22.04

Gradle requires Java SE 8 or later to be installed on the machine.

First, update your local package index with the following command:

sudo apt update

Then, install OpenJDK on your server with the command below:

sudo apt install default-jre -y

Verify your Java installation by checking its version:

java -version
Output
openjdk version "11.0.18" 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

Install Gradle on Ubuntu 22.04

At this point, you need to visit the Gradle Releases page and download the latest version on your Ubuntu 22.04 server.

Download the Gradle Build Tool

Use the following wget command to download the Gradle in the /tmp directory:

sudo wget https://downloads.gradle-dn.com/distributions/gradle-8.0.2-bin.zip -P /tmp

When your download is completed, extract your file in the /opt/gradle directory:

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

Set up Environment Variables

At this point, you need to configure the environmental variable PATH on Ubuntu 22.04. To do this, run the command below:

export PATH=$PATH:/opt/gradle/gradle-8.0.2/bin

Verify Gradle Installation

At this point, your Gradle installation is completed, you can verify it by checking its version on Ubuntu 22.04:

gradle -v
Output
Welcome to Gradle 8.0.2!

Here are the highlights of this release:
 - Improvements to the Kotlin DSL
 - Fine-grained parallelism from the first build with configuration cache
 - Configurable Gradle user home cache cleanup

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


------------------------------------------------------------
Gradle 8.0.2
------------------------------------------------------------

Build time:   2023-03-03 16:41:37 UTC
Revision:     7d6581558e226a580d91d399f7dfb9e3095c2b1d

Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.18 (Ubuntu 11.0.18+10-post-Ubuntu-0ubuntu122.04)
OS:           Linux 5.15.0-46-generic amd64

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

Conclusion

At this point, you have learned to Set up Gradle on Ubuntu 22.04.

Hope you enjoy it. Please subscribe to us on Facebook and Twitter.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!