How to Install Gradle on Ubuntu 18.04

How to install Gradle on Ubuntu 18.04
How to install Gradle on Ubuntu 18.04

Install Gradle on Ubuntu

Gradle is a free and opensource general purpose build tool used mainly for Java projects. It uses Groovy which is dynamic, object-oriented programming language to define projects and build scripts for Java language. Gradle is also used for building Android projects in Android Studio. In this tutorial, you are going to learn how to install Gradle on Ubuntu 18.04.

Prerequisites

Before you start to install Gradle on Ubuntu. You must have the non-root user account on your server/desktop with sudo privileges.

Install OpenJDK

First update apt package manager index in Ubuntu typing following command:

sudo apt update

Gradle requires Java to be installed on your system. To install OpenJDK 8 run following command in terminal:

sudo apt install openjdk-8-jdk

Confirm the OpenJDK installation typing following command:

java -version

Download Gradle

You can download Gradle from official Gradle release page. The latest Gradle version available is 5.1. You can check visiting there website if new version is available.

To download Gradle 5.1 using wget run following command:

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

Now unzip downloaded zip file using following command:

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

Setup Environment Variables

PATH Environment variable should include Gradle directory. So we should create gradle.sh file inside /etc/profile.d/ directory. To create file run following command:

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

Now paste following code inside above file.

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

Save the file and close the file.

Now make script file executable using following command:

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

Load the environment variables using following command:

source /etc/profile.d/gradle.sh

Verify Installation

Now verify the installation of Gradle using following command.

gradle -v

And the output should look like:

Welcome to Gradle 5.1!

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 https://docs.gradle.org/5.1/release-notes.html


------------------------------------------------------------
Gradle 5.1
------------------------------------------------------------

Build time:   2018-12-29 11:48:43 UTC
Revision:     e0824aec8a0f5462fc5fd9872664dbc7fc6e5abf

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

Conclusion

You have successfully learned how to install Gradle on Ubuntu 18.04. If you have any queries regarding this please dont forget to comment below.