How to install Gradle on Ubuntu 18.04

s2 0

Gradle is a universal build tool mainly used for Java projects. It combines the best of both Ant and Maven. Unlike its predecessors, which used XML for scripting, Gradle uses Groovy
, a dynamic, object-oriented programming language for the Java platform to define the project and create scripts.

In this tutorial, we are going to show you how to install Gradle on Ubuntu 18.04. The same instructions apply to Ubuntu 16.04 and all Ubuntu-based distributions, including Linux Mint and Elementary OS.


In order to be able to install packages on your Ubuntu system, you must be logged in as a user with sudo rights.

Install Gradle on Ubuntu

The following sections provide step-by-step instructions for installing the latest version of Gradle on Ubuntu 18.04. We will be downloading the latest version of Gradle from their official website.

1. Install OpenJDK

Gradle requires Java JDK or JRE version 7 or higher to be installed. We install OpenJDK 8.

Installing Java is pretty straightforward. Start by updating the package index:

sudo apt update

Install the OpenJDK package by typing:

sudo apt install openjdk-8-jdk

Verify the Java installation by running the following command that outputs the Java version:

java -version

The output should look something like this:

openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.18.04.1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

2. Download Gradle

At the time of this writing, it is the latest version from Gradle 5.0. Before proceeding to the next step, you should review the Gradle Publications Page
to see if a newer version is available.

Start by downloading the Gradle-only ZIP file in the /tmp Directory with the following wget

wget -P /tmp

As soon as the download is complete, unzip the zip file in /opt/gradle Directory:

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

Make sure the Gradle files have been extracted by editing the /opt/gradle/gradle-5.0 Directory:

ls /opt/gradle/gradle-5.0
bin  getting-started.html  init.d  lib  LICENSE  media  NOTICE

3. Set up environment variables

Next we need to configure the PATH environment variable to contain the Gradle-bin directory. To do this, open your text editor and create a new file called within the /etc/profile.d/ Directory.

sudo nano /etc/profile.d/

Paste the following configuration:

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

Save and close the file. This script is provided when the shell is started.

Make the script executable by printing the following chmod

sudo chmod +x /etc/profile.d/

Load the environment variables with the source command:

source /etc/profile.d/

4. Check the Gradle installation

To verify that Gradle is properly installed, use the gradle -v Command showing the Gradle version:

gradle -v

You should see something like this:

Welcome to Gradle 5.0!

Here are the highlights of this release:
 - Kotlin DSL 1.0
 - Task timeouts
 - Dependency alignment aka BOM support
 - Interactive `gradle init`

For more details see

Gradle 5.0

Build time:   2018-11-26 11:48:43 UTC
Revision:     7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987

Kotlin DSL:   1.0.4
Kotlin:       1.3.10
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_181 (Oracle Corporation 25.181-b13)
OS:           Linux 4.15.0-36-generic amd64

That’s it. The latest version of Gradle is now installed on your Ubuntu system.


You have successfully installed Gradle on your Ubuntu 18.04. You can now visit the official Gradle documentation
Page and learn how to get started with Gradle.

If you run into any problem or have any feedback, please leave a comment below.