Linux

How to Install Gradle on Ubuntu 20.04

How to Install Gradle on Ubuntu 20.04

Gradle is a general purpose tool used to build, automate, and deliver software. This is mainly used for Java, C ++, and Swift projects.

Gradle combines the best features of Ant and Maven. Unlike its predecessor, which uses XML for scripts, Gradle uses Groovy, a dynamic object-oriented programming language for the Java platform to define projects and build scripts.

This guide explains how to install Gradle on Ubuntu 20.04. We will download the latest Gradle release from their official website.

Precondition

The instructions assume that you are logged in as root or as a user with sudo privileges.

Install OpenJDK

Gradle requires Java SE 8 or newer to be installed on the machine.

Enter the following command to install OpenJDK 11:
sudo apt update
sudo apt install openjdk-11-jdk

Verify the Java installation by printing a Java version:

java -version

The output will look like this:

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)

Downloading Gradle

At the time of writing this article, the latest version of Gradle is 6.5.1. Before proceeding with the next step, check the Gradle release page to see if a newer version is available.

Download the binary Gradation zip file only in the / tmp directory using the following wget command:
VERSION=6.5.1
wget https://services.gradle.org/distributions/gradle-${VERSION}-bin.zip -P /tmp

After the download is complete, open the zip file in the / opt / gradle directory:

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

Gradle is regularly updated with security patches and new features. To have more control over versions and updates, we will create a symbolic link with the latest name, which points to the Gradle installation directory:

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

Then, when upgrading Gradle, open a newer version and change the symlink to direct it.

Setting up Environmental Variables

We need to add the Gradle Trash directory to the PATH environment variable system. To do this, open your text editor and create a new file named gradle.sh in 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/latest
export PATH=${GRADLE_HOME}/bin:${PATH}

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

Make the script executable:

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

Load the environment variable in the current shell session using the source command:

source /etc/profile.d/gradle.sh

Verifying Gradle Installation

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

gradle -v

You should see something like the following:

Output :

Welcome to Gradle 6.5.1!

Here are the highlights of this release:
 - Experimental file-system watching
 - Improved version ordering
 - New samples

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


------------------------------------------------------------
Gradle 6.5.1
------------------------------------------------------------

Build time:   2020-06-30 06:32:47 UTC
Revision:     66bc713f7169626a7f0134bf452abde51550ea0a

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.7 (Ubuntu 11.0.7+10-post-Ubuntu-3ubuntu1)
OS:           Linux 5.4.0-26-generic amd64

There she is. You have installed the latest version of Gradle on your Ubuntu system, and you can start using it.

Conclusion

We have shown you how to install Gradle on Ubuntu 20.04. You can now visit the official Gradle Documentation page and learn how to get started with Gradle.

If you experience problems or get feedback, leave a comment below.

Related posts

How to Install and Configure Fail2ban on Ubuntu 20.04

Linux

How to install Linux Kernel 5.7 on Ubuntu

Linux

How to install Chef Server and Chef Client on Ubuntu 20.04

Linux

How to Install Xrdp Server (Remote Desktop) on Ubuntu 20.04

Linux

How to delete a Terminal on Ubuntu and other Linux distributions

Linux

How to Install the Open Source Computer Vision Library (OpenCV) on CentOS 8

Linux

How to Install Laravel on Ubuntu 20.04

Linux

How to use BleachBit on Linux

Linux

How to Install the ElkArte Forum Software on Ubuntu 20.04

Linux