How To Install Gradle on Ubuntu 18.04 / 16.04, Linux Mint 19 & Debian 9

0

Gradle is an open-source build automation tool used for Java, Groovy and Scala development. It builds upon the concepts of Apache Ant and Apache Maven. Unlike Apache Maven which uses XML for declaring project configurations, Gradle uses Groovy, a dynamic, object-oriented programming language to define the project configurations.

In this post, we will install Gradle on Ubuntu 18.04 / Ubuntu 16.04, Linux Mint 19 & Debian 9.

Prerequisites

Gradle’s only requirement is Java JDK or JRE version 7 or above to be installed.

If you prefer Oracle Java JDK over OpenJDK then follow the post about installation of Oracle Java on Ubuntu 18.04 / 16.04, Linux Mint 19 & Debian 9. Here, I will go with OpenJDK 8.

Update the repository index.

sudo apt update

Install the OpenJDK package by using the apt command.

sudo apt install -y openjdk-8-jdk-headless

Verify the Java installation by executing the following command.

java -version

Output:

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

Install other supported packages.

sudo apt install -y wget unzip

Install Gradle on Ubuntu

Download the latest version of Gradle (V5.2.1) from the official site. Download Gradle Binary-only zip file.

OR

Use the below command in terminal to download Gradle v5.2.1.

cd /tmp
wget https://services.gradle.org/distributions/gradle-5.2.1-bin.zip

Extract the downloaded zip file in the /opt/gradle directory.

unzip gradle-*.zip

Extract zipped package using unzip command.

sudo mkdir /opt/gradle
sudo cp -pr gradle-*/* /opt/gradle

Verify the extracted files by listing the /opt/gradle/ directory.

ls /opt/gradle/

Output:

LICENSE  NOTICE  bin  getting-started.html  init.d  lib  media

Setup environment variables

We will now configure the PATH environment variable to include the Gradle’s bin directory. To do that, 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:

export PATH=/opt/gradle/bin:${PATH}

Save and close the file.

Make the script executable by using the chmod command.

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

Load the environment variables for the current session by using the following command.

source /etc/profile.d/gradle.sh

Verify the Gradle installation

To validate the Gradle installation, use the below command.

gradle -v

Output:

Welcome to Gradle 5.2.1!

Here are the highlights of this release:
 - Define sets of dependencies that work together with Java Platform plugin
 - New C++ plugins with dependency management built-in
 - New C++ project types for gradle init
 - Service injection into plugins and project extensions

For more details see https://docs.gradle.org/5.2.1/release-notes.html


------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_191 (Oracle Corporation 25.191-b12)
OS:           Linux 4.15.0-1027-gcp amd64

Conclusion

You have successfully installed Gradle (v5.2.1) on your Ubuntu 18.04 / Ubuntu 16.04, Linux Mint 19 & Debian 9. You can go to the official Gradle Documentation page to learn how to get started with Gradle.

Further Reading

You might also like

How To Install Gradle on Ubuntu 18.04 / 16.04, Linux Mint 19 & Debian 9

0