How To Install Gradle on Ubuntu

DevOpsDevOps News

YOUR COSMETIC CARE STARTS HERE

Find the Best Cosmetic Hospitals

Trusted • Curated • Easy

Looking for the right place for a cosmetic procedure? Explore top cosmetic hospitals in one place and choose with confidence.

“Small steps lead to big changes — today is a perfect day to begin.”

Explore Cosmetic Hospitals Compare hospitals, services & options quickly.

✓ Shortlist providers • ✓ Review options • ✓ Take the next step with confidence

Gradle is a free and open-source build automation tool that builds on concepts from Apache Ant and Apache Maven while replacing XML-based configuration with a Groovy-based Domain Specific Language (DSL). It supports the full development lifecycle and is widely used for Java, Android, and polyglot projects.

This guide walks through installing Gradle on Ubuntu manually from the official binary distribution — the approach that gives you full control over which version is installed.

Note: The commands below were originally demonstrated on Ubuntu 16.04 (Xenial) with Gradle 3.4.1. The procedure is the same on modern Ubuntu releases, but you should substitute the current Gradle release version from gradle.org/releases when you run through these steps.

Prerequisites

  • Ubuntu (any currently supported LTS release)
  • A user account with sudo privileges, or root access
  • Internet access to download the Gradle binary
  • Java Development Kit (JDK) 8 or later (Gradle requires JDK 7 as a minimum; JDK 8+ is recommended)

Step 1 — Update System Package Repositories

Before installing any new software, refresh your local package index to make sure you pull the latest metadata:

sudo apt-get updateCode language: JavaScript (javascript)

Step 2 — Install OpenJDK 8

Gradle requires a JDK to run. Install OpenJDK 8 (or a later version available in your Ubuntu repositories) with:

sudo apt-get install openjdk-8-jdk -yCode language: JavaScript (javascript)

After the installation completes, confirm the JDK is available:

java -version

Expected output (version numbers will differ depending on the build installed):

openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)Code language: CSS (css)

If you want to install a newer JDK version (11, 17, 21, etc.), substitute the appropriate package name, for example openjdk-21-jdk.

Step 3 — Download the Gradle Binary Distribution

Visit gradle.org/releases to find the URL for the current stable release. Then use wget to download the -bin.zip archive (which contains the Gradle binaries and command-line tools, but not the source or documentation). Replace 3.4.1 in the example below with the version you want to install:

wget https://services.gradle.org/distributions/gradle-3.4.1-bin.zipCode language: JavaScript (javascript)

The download is around 60–100 MB depending on the Gradle release.

Step 4 — Create the Installation Directory

It is conventional to install manually managed software under /opt. Create a dedicated directory for Gradle:

sudo mkdir /opt/gradle

Step 5 — Extract the Archive

If unzip is not already installed, install it first:

sudo apt-get install unzip -yCode language: JavaScript (javascript)

Then extract the downloaded archive directly into /opt/gradle:

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

This creates a versioned subdirectory, for example /opt/gradle/gradle-3.4.1/, which makes it easy to maintain multiple Gradle versions side by side.

Step 6 — Configure the PATH Environment Variable

Add the Gradle bin directory to your PATH so that the gradle command is available system-wide. There are two ways to do this:

Option A — Current session only (temporary)

export PATH=$PATH:/opt/gradle/gradle-3.4.1/binCode language: JavaScript (javascript)

This sets the variable for the current shell session only. It will be lost when you close the terminal.

Option B — Persistent across sessions (recommended)

Create a profile script so the PATH is set automatically for all users at login:

echo 'export PATH=$PATH:/opt/gradle/gradle-3.4.1/bin' | sudo tee /etc/profile.d/gradle.sh
sudo chmod +x /etc/profile.d/gradle.sh
source /etc/profile.d/gradle.shCode language: PHP (php)

Alternatively, add the export line to your personal ~/.bashrc or ~/.profile and run source ~/.bashrc.

Step 7 — Verify the Installation

Confirm that Gradle is installed and accessible:

gradle -v

You should see output similar to:

------------------------------------------------------------
Gradle 3.4.1
------------------------------------------------------------
Build time:   2017-03-03 19:45:41 UTC
Revision:     9eb76efdd3d034dc506c719dac2955efb5ff9a93
Groovy:       2.4.7
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_121 (Oracle Corporation 25.121-b13)
OS:           Linux 4.4.0-21-generic amd64Code language: CSS (css)

The version, Groovy runtime, Ant version, and JVM details will reflect what is actually installed on your system.

Upgrading Gradle in the Future

Because the binary was extracted into a versioned directory (/opt/gradle/gradle-X.Y.Z/), upgrading is straightforward:

  1. Download the new release zip from gradle.org/releases.
  2. Extract it into /opt/gradle/ alongside the existing version.
  3. Update the PATH in /etc/profile.d/gradle.sh (or wherever you defined it) to point to the new version’s bin directory.
  4. Re-source the profile file or log out and back in.

Alternatively, consider using the Gradle Wrapper (gradlew) in your projects, which pins each project to a specific Gradle version automatically and is the approach recommended by the Gradle team for reproducible builds.

Summary

StepCommand
Update package indexsudo apt-get update
Install JDKsudo apt-get install openjdk-8-jdk -y
Download Gradlewget https://services.gradle.org/distributions/gradle-X.Y.Z-bin.zip
Create directorysudo mkdir /opt/gradle
Extract archivesudo unzip -d /opt/gradle gradle-X.Y.Z-bin.zip
Set PATHexport PATH=$PATH:/opt/gradle/gradle-X.Y.Z/bin
Verifygradle -v

Gradle’s manual binary installation gives you precise version control and is straightforward to automate with configuration management tools such as Ansible or Chef for fleet deployments.

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x