How to Install Gradle on Ubuntu 20.04/18.04/16.04 LTS

In this article, We are going to perform How to Install Gradle on Ubuntu 20.04/18.04/16.04 LTS or any other cloud platform like AWS EC2, Azure VM, Google Compute Cloud, etc., with preinstalled ubuntu.

Introduction

Gradle is Free and Open Source build automation tool. It is used to build any type of language code.

Prerequisites

  • Ubuntu Server 20.04/18.04/16.04 LTS
  • SSH access with sudo privileges

Install JDK on Ubuntu

Install OpenJDK 8 or 11.

$ sudo apt-get update
$ sudo apt install openjdk-8-jdk

OR

Install OpenJDK 11

$ sudo apt install openjdk-11-jdk

Lets verify java version

$ java -version

Output:

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

How to Install Gradle on Ubuntu

Here we are downloading and installing Gradle 6.4 Version, if you want to download latest or specific version go through Gradle Download page.

Download the gradle setup in /tmp directory using below command,

$ cd /tmp
$ sudo wget https://downloads.gradle-dn.com/distributions/gradle-6.4.1-bin.zip

unzip the gradle binary setup in /opt/gradle directory

$ unzip -d /opt/gradle gradle-6.4.1-bin.zip

OR

If you want to install default gradle version for ubuntu , you can install gradle using PPA repository

Run below commands to Add PPA repository for gradle and install

$ sudo apt -y install vim apt-transport-https dirmngr wget software-properties-common

$ sudo add-apt-repository ppa:cwchien/gradle

$ sudo apt update

$ sudo apt -y install gradle

Configure Environment Variable

To configure the environment variable open the below file:
$ sudo nano /etc/profile.d/gradle.sh
Paste the below path into the file:
/etc/profile.d/gradle.sh
export PATH=$PATH:/opt/gradle/gradle-6.4.1/bin

Load the environment variable using below command

$ source /etc/profile.d/gradle.sh

We have configured environment for gradle.

Verify Gradle Version

Now verify the Gradle version using below command.

$ gradle -v

Output:

------------------------------------------------------------
Gradle 6.4.1
------------------------------------------------------------

Build time: 2020-05-15 19:43:40 UTC
Revision: 1a04183c502614b5c80e33d603074e0b4a2777c5

Kotlin: 1.3.71
Groovy: 2.5.10
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 11.0.7 (Azul Systems, Inc. 11.0.7+10-LTS)
OS: Linux 5.4.0-1009-aws amd64

Conclusion

In this article, We have covered How to Install Gradle on Ubuntu 20.04/18.04/16.04 LTS, Configure environment variable for Gradle, verify gradle version.

Related Articles:

How to Install Java on Ubuntu 20.04 LTS

Reference

Gradle Official link

Aniruddha Kanade

I am Shivdas Kanade working as Senior Site Reliability Engineer (Cloud and DevOps ). Believes in Sharing Knowledge.

Leave a Comment

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

Share via
Copy link