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

#1. 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.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

#2. 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

To download specific version of gradle use below syntax

sudo wget https://services.gradle.org/distributions/gradle-${VERSION}-bin.zip

Here we are downloading gradle 7.0 on Ubuntu

sudo wget https://services.gradle.org/distributions/gradle-7.0-bin.zip

Install unzip on Ubuntu if not installed

sudo apt install unzip

unzip the gradle binary setup in /opt/gradle directory use below syntax

sudo unzip -d /opt/gradle gradle-${VERSION}-bin.zip

To unzip gradle setup in /opt/gradle directory

sudo unzip -d /opt/gradle gradle-7.0-bin.zip

To update the gradle version and security updated, create symlink latest

sudo ln -s /opt/gradle/gradle-${VERSION} /opt/gradle/latest
sudo ln -s /opt/gradle/gradle-7.0 /opt/gradle/latest

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

#3. Configure Environment Variable for Gradle

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 GRADLE_HOME=/opt/gradle/latest
export PATH=$PATH:/opt/gradle/gradle-7.0/bin

Load the environment variable using below command

source /etc/profile.d/gradle.sh

Give the excutable permission to above script

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

We have configured environment for gradle.

#4. Verify Gradle Version

Now verify the Gradle version on Ubuntu using below command.

gradle -v

Output:

------------------------------------------------------------
Gradle 7.0
------------------------------------------------------------

Build time: 2021-04-09 22:27:31 UTC
Revision: d5661e3f0e07a8caff705f1badf79fb5df8022c4

Kotlin: 1.4.31
Groovy: 3.0.7
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.10 (Ubuntu 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OS: Linux 5.4.0-1038-aws amd64

We have covered How to Install Gradle on Ubuntu.

Uninstall Gradle from Ubuntu 20.04 LTS

To uninstall Gradle from Ubuntu, if you installed gradle by downloading gradle zip setup, remove gradle directory from /opt

sudo rm -rf /opt/gradle

Remove the gradle.sh from /etc/profile.d directory

sudo rm -rf /etc/profile.d/gradle.sh

Run below commands if you have install gradle using APT

sudo apt-get remove  gradle
sudo apt-get remove --auto-remove gradle
sudo apt-get purge gradle
sudo apt-get purge --auto-remove gradle

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

How to Install Maven on Ubuntu 20.04 LTS

Reference

Gradle Official link

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

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

Share via
Copy link
Powered by Social Snap