Website Vidya
Linux & ServersStep-by-Step Guide

How to Install Gradle on Ubuntu 24.04

Step-by-step tutorial to install Gradle on Ubuntu 24.04 LTS using official binary distributions, OpenJDK 17 setup, and environment PATH configuration.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Install Gradle on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

6 min read

Step-by-step tutorial to install Gradle on Ubuntu 24.04 LTS using official binary distributions, OpenJDK 17 setup, and environment PATH configuration.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Installing Required Java Development Kit (OpenJDK)
  • Step 2: Verifying the Java Installation and Setting JAVA_HOME
Grounded in full engineering runbookWebsiteVidya AI Engine

Modern application engineering demands rapid compilation, automated test execution, and declarative dependency management across diverse tech stacks. When you install gradle on ubuntu 24.04, you deploy an advanced build automation engine that combines the flexibility of Apache Ant with the convention-over-configuration paradigm of Apache Maven, enhanced by a high-performance incremental build daemon and Groovy/Kotlin domain-specific languages (DSLs).

While the default Ubuntu APT archive includes a gradle package, distribution packages are frequently several major releases behind upstream and lack support for contemporary Java 21 features. Installing Gradle via the official upstream binary distribution under /opt/gradle/ guarantees that you receive the latest build caching capabilities, configuration caching optimizations, and Android build tools compatibility.

In addition to standard Java compilation, Gradle is the official build tool for the Android operating system and powers millions of enterprise microservices built on Spring Boot, Quarkus, and Micronaut. Its build cache saves hours of developer time by reusing outputs from previous builds across distributed continuous integration (CI) agents.

This technical guide walks you through the entire installation process on Ubuntu 24.04 LTS. You will install the OpenJDK 17 compiler prerequisites, download and verify the official Gradle binary distribution zip, configure persistent environment variables in /etc/profile.d/gradle.sh, understand daemon memory tuning, and build a sample Java application from the command line.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A desktop or server running Ubuntu 24.04 LTS.
  • A user account with active sudo administrative privileges.
  • Java Development Kit (OpenJDK 17 or OpenJDK 21) installed or ready to install.
  • Access to a command-line terminal and active Internet connectivity.

Step 1: Installing Required Java Development Kit (OpenJDK)

Gradle requires a Java Development Kit (JDK) version 8 or higher to execute. For Ubuntu 24.04 LTS, OpenJDK 17 (LTS) or OpenJDK 21 (LTS) is strongly recommended for enterprise stability, security maintenance, and modern Java language support.

Advertisement

Note that a Java Runtime Environment (JRE) alone is insufficient; compiling Java source code into bytecode requires the complete compiler toolchain (javac) found within the JDK.

Update your package repository index and install openjdk-17-jdk alongside utility tools like wget and unzip.

# Refresh package repository index
sudo apt update

# Install OpenJDK 17 JDK, wget, and unzip
sudo apt install -y openjdk-17-jdk wget unzip

Step 2: Verifying the Java Installation and Setting JAVA_HOME

Confirm that the Java compiler (javac) and Java runtime environment (java) are properly installed and available on your system path.

Setting the JAVA_HOME environment variable ensures that Gradle and companion build daemons locate your exact JDK installation directory without ambiguity.

Advertisement

Execute the following commands to check versions and configure JAVA_HOME in your shell profile.

# Verify Java runtime version
java -version

# Verify Java compiler version
javac -version

# Check default Java installation path
update-java-alternatives -l

# Export JAVA_HOME in your environment
echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" | sudo tee -a /etc/profile.d/jdk.sh
source /etc/profile.d/jdk.sh

Step 3: Downloading Official Gradle Binary Distribution

Visit Gradle's official distribution portal to select the latest binary-only release (bin.zip), which contains the Gradle runtime without redundant documentation or source code.

Always choose the binary release over source bundles for standard developer workstations. Download the official archive directly into /tmp using wget.

# Define Gradle version variable
GRADLE_VER="8.7"

# Navigate to temporary directory
cd /tmp

# Download official binary release zip
wget https://services.gradle.org/distributions/gradle-${GRADLE_VER}-bin.zip

Step 4: Extracting Gradle into /opt/gradle

In alignment with Linux Filesystem Hierarchy Standards (FHS), third-party standalone software packages should reside in the /opt directory.

Create the /opt/gradle directory and extract the downloaded zip archive into it.

Creating a symbolic link /opt/gradle/latest pointing to your active version allows seamless future upgrades without changing system environment variable paths.

# Create target directory
sudo mkdir -p /opt/gradle

# Unzip archive into /opt/gradle
sudo unzip -d /opt/gradle /tmp/gradle-${GRADLE_VER}-bin.zip

# Create convenient symlink to active version
sudo ln -sfn /opt/gradle/gradle-${GRADLE_VER} /opt/gradle/latest

# Verify extracted directory contents
ls -la /opt/gradle/latest

Step 5: Configuring System-Wide Environment Variables

To allow all users on your system to execute the gradle command from any terminal directory, configure the PATH environment variable by creating a shell script in /etc/profile.d/.

This script automatically exports /opt/gradle/latest/bin upon user login, ensuring full multi-user availability.

Make the script executable and source it in your active terminal.

# Create environment configuration script
sudo tee /etc/profile.d/gradle.sh << 'EOF'
export GRADLE_HOME=/opt/gradle/latest
export PATH=${GRADLE_HOME}/bin:${PATH}
EOF

# Make the environment script executable
sudo chmod +x /etc/profile.d/gradle.sh

# Source the script in current terminal session
source /etc/profile.d/gradle.sh

Step 6: Verifying Gradle Installation and Daemon Status

Execute the gradle -v command in your terminal to verify that Gradle is properly configured.

The output displays the installed Gradle version, Kotlin DSL version, Groovy engine version, JVM architecture details, and active operating system flags.

Gradle utilizes a background daemon process to keep build information cached in memory, slashing subsequent compilation times.

# Check Gradle version and build runtime details
gradle -v

Step 7: Tuning Gradle Daemon Performance and Memory Limits

On developer laptops or production build servers with limited RAM, the Gradle daemon can consume significant memory if left unconfigured.

You can configure global build properties by creating a configuration file at ~/.gradle/gradle.properties. Setting maximum heap size (-Xmx2g), parallel execution, and build caching significantly speeds up compilation cycles.

Apply the following optimized properties for daily software development.

# Create user Gradle configuration directory
mkdir -p ~/.gradle

# Configure optimized build parameters
cat << 'EOF' > ~/.gradle/gradle.properties
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -XX:+UseG1GC
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.daemon=true
EOF

Step 8: Creating and Building a Sample Java Project

Verify end-to-end functionality by creating an empty directory and running the interactive gradle init project generator.

Select a basic Java application project, compile it, and execute the generated binary using the Gradle Wrapper.

The Gradle Wrapper (gradlew) ensures that your team executes identical build environments without requiring manual global Gradle installations on client machines.

# Create project directory
mkdir ~/my-gradle-app && cd ~/my-gradle-app

# Initialize a basic Java application
gradle init --type java-application --dsl kotlin --test-framework junit-jupiter --project-name my-app --package com.example

# Build the application
./gradlew build

# Run the compiled application
./gradlew run

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

Command 'gradle' not found after configuring /etc/profile.d/gradle.sh

Resolution: Environment scripts in /etc/profile.d/ are read during shell login. Run source /etc/profile.d/gradle.sh in your active terminal, or log out and log back in to reload your shell session.

Gradle build fails with 'Unsupported class file major version'

Resolution: This indicates that your installed Gradle version is too old for your active JDK version. Upgrade to Gradle 8.5 or higher when compiling with OpenJDK 21, or point JAVA_HOME to OpenJDK 17.

Gradle daemon consumes excessive system memory on low-RAM servers

Resolution: Create a local configuration file at ~/.gradle/gradle.properties and add org.gradle.jvmargs=-Xmx1024m -XX:MaxMetaspaceSize=256m and org.gradle.daemon=false to limit memory usage.

Security Best Practices and Hardening

Always verify SHA256 checksums of Gradle binary distributions against published hashes on services.gradle.org before extracting archives.

Use the Gradle Wrapper (./gradlew) within version-controlled repositories to ensure developers execute identical build toolchain versions.

Audit third-party dependencies resolved by Gradle from Maven Central using dependency verification (--write-verification-metadata).

Avoid running gradle build commands as the root user, as custom build scripts could execute arbitrary system commands with administrative privileges.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
Maven uses declarative XML configuration files (pom.xml) with fixed lifecycle phases, whereas Gradle uses Groovy or Kotlin DSLs with incremental task execution and high-speed build caching.
Yes. If a project contains the Gradle Wrapper (gradlew and gradlew.bat), running ./gradlew build automatically downloads and uses the project's exact required Gradle version.
Download the newer binary zip to /tmp, extract it into /opt/gradle/gradle-<new-version>, and update the path in /etc/profile.d/gradle.sh.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout