UbuntuUbuntu Based

How To Install Gradle on Ubuntu 24.04 LTS

Install Gradle on Ubuntu 24.04

Gradle is a powerful build automation tool that simplifies the development process for large-scale applications, particularly those built with Java, Kotlin, Scala, Android, Groovy, C++, or Swift. Its ability to streamline tasks such as compiling, testing, packaging, and deploying applications makes it an indispensable tool for developers. In this article, we will guide you through the process of installing Gradle on Ubuntu 24.04 LTS, ensuring that you can leverage its capabilities to enhance your development workflow.

Introduction to Gradle and Ubuntu 24.04 LTS

Gradle’s flexibility and integration with various platforms make it a preferred choice for managing complex build processes. Ubuntu 24.04 LTS, with its robust and stable environment, provides an ideal platform for developers to work with Gradle. By installing Gradle on Ubuntu, you can automate tasks efficiently, ensuring faster project delivery and better collaboration among team members.

Why Use Gradle?

  • Multi-Language Support: Gradle supports a wide range of programming languages, making it versatile for diverse projects.
  • Efficient Build Process: It optimizes the build process by only rebuilding what has changed, saving time and resources.
  • Extensive Plugin Ecosystem: Gradle’s plugin ecosystem allows for easy integration with other tools and platforms, enhancing its functionality.

Prerequisites for Installing Gradle

Before proceeding with the installation, ensure your system meets the necessary prerequisites:

  • Ubuntu 24.04 LTS: Ensure you are running Ubuntu 24.04 LTS.
  • Java Dependency: Gradle requires Java to function. You will need to install a compatible Java Development Kit (JDK).
  • Sufficient Privileges: You need administrative privileges to install software on your system.

Installing OpenJDK on Ubuntu 24.04 LTS

To install Gradle, you first need to install OpenJDK, as Gradle relies on Java for its operations.

Step 1: Update Package Index

Open your terminal and update the package index to ensure you have access to the latest packages:

sudo apt update

Step 2: Install OpenJDK

Install OpenJDK using the following command. You can choose between different versions, but OpenJDK 21 is recommended for its compatibility:

sudo apt install openjdk-21-jdk

Alternatively, you can install the default JDK if you prefer:

sudo apt install default-jdk -y

Step 3: Verify Java Installation

After installation, verify that Java is correctly installed by checking its version:

java -version

This command will display the version of Java installed on your system.

Downloading and Installing Gradle

Now that Java is installed, you can proceed with downloading and installing Gradle.

Method 1: Installing Gradle from the Official Zip File

This method allows you to install the latest version of Gradle directly from the official Gradle website.

Step 1: Download Gradle

Navigate to the Gradle release page and copy the direct download link for the latest binary-only zip file. Alternatively, you can use wget to download it directly:

wget https://services.gradle.org/distributions/gradle-8.12-bin.zip

Step 2: Extract Gradle

Extract the downloaded zip file to a system-wide directory like /opt/gradle:

sudo unzip -d /opt/gradle gradle-8.12-bin.zip

Method 2: Installing Gradle Using APT

Ubuntu’s standard repository includes an older version of Gradle that can be installed using the APT package manager.

sudo apt install gradle -y

Verify the installation with:

gradle --version

Method 3: Installing Gradle Using Snap

You can also install Gradle using the Snap package manager, which is pre-installed on Ubuntu.

sudo snap install gradle --classic

Verify the installation with:

sudo snap run gradle --version

Configuring Environment Variables

To ensure Ubuntu recognizes the Gradle installation, you need to configure environment variables.

Step 1: Create a Script

Create a script file in the /etc/profile.d/ directory to set environment variables:

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

Add the following lines to the script:

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

Step 2: Make the Script Executable

Make the script executable with:

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

Step 3: Load Environment Variables

Load the environment variables using:

source /etc/profile.d/gradle.sh

Verifying Gradle Installation

After setting up the environment variables, verify that Gradle is correctly installed by checking its version:

gradle -v

This command will display the version of Gradle installed on your system.

Congratulations! You have successfully installed Gradle. Thanks for using this tutorial for installing Gradle on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Gradle website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button