Read in 3 minutes

last updated 

How to install Gradle on Ubuntu 18.04

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

In this tutorial we will show you how to install Gradle on Ubuntu 18.04. The same instructions apply for Ubuntu 16.04 and any Ubuntu based distribution, including Linux Mint and Elementary OS.

Prerequisites

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

Installing Gradle on Ubuntu

The following sections provide a step by step instructions about how to install the latest Gradle version on Ubuntu 18.04. We’ll be downloading the latest release of Gradle from their official website.

1. Install OpenJDK

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

The installation of Java is pretty simple. 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 which will print 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)

If you prefer Oracle Java over OpenJDK follow these instructions to install Oracle Java.

2. Download Gradle

At the time of writing this article, the latest version of Gradle is 4.10.2. Before continuing with the next step you should check the Gradle releases page to see if a newer version is available.

Start by downloading the Gradle Binary-only zip file in the /tmp directory using the following wget command:

wget https://services.gradle.org/distributions/gradle-4.10.2-bin.zip -P /tmp

Once the download is completed, extract the zip file in the /opt/gradle directory:

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

Verify that the Gradle files are extracted by listing the /opt/gradle/gradle-4.10.2 directory:

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

3. Setup environment variables

Next, we’ll need to configure the PATH environment variable to include the Gradle bin directory. To do so, open your text editor and create a new file named gradle.sh inside of the /etc/profile.d/ directory.

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

Paste the following configuration:

/etc/profile.d/gradle.sh
export GRADLE_HOME=/opt/gradle/gradle-4.10.2
export PATH=${GRADLE_HOME}/bin:${PATH}

Save and close the file. This script will be sourced at shell startup.

Make the script executable by typing:

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

Load the environment variables using the following command:

source /etc/profile.d/gradle.sh

4. Verify the Gradle installation

To validate that Gradle is installed properly use the gradle -v command which will display the Gradle version:

gradle -v

You should see something like the following:

------------------------------------------------------------
Gradle 4.10.2
------------------------------------------------------------

Build time:   2018-09-19 18:10:15 UTC
Revision:     b4d8d5d170bb4ba516e88d7fe5647e2323d791dd

Kotlin DSL:   1.0-rc-6
Kotlin:       1.2.61
Groovy:       2.4.15
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 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.

Conclusion

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 hit a problem or have a feedback, leave a comment below.