How To Install Gradle on Ubuntu 20.04

On this tutorial we will learn how to install Gradle version 6.4 on Ubuntu 20.04 LTS
Introduction
Gradle is a general-purpose build automation tool for multi-language software development. Gradle is used to build, automate, and deliver software. It controls the development process in the tasks of compilation and packaging to testing, deployment, and publishing. It is primarily used for Java, C++, Kotlin, Groovy, Scala and Swift projects. On this tutorial, we will learn how to install Gradle on Ubuntu 20.04 LTS operating systrm.
Gradle Installation On Ubuntu 20.04 LTS
The Gradle installation process will be divided into several steps, as follow :
- Prerequisite
- Installing Java
- Download Gradle Source File and Extract
- Make and setting up Gradle environemnt variables
- Verify Gradle Installation
Prerequisite
- Ubuntu 20.04 LTS system
- User account with sudo privillege
- Sufficient disk space and good network to access Gradle source file
Installing Java
By default, Gradle requires a Java environment to live with on the system. Gradle needs the Java codebase to interpret Groovy code. The OpenJDK installation has been discussed on previous article.
sudo apt update sudo apt install openjdk-11-jdk
Verify OpenJDK installation by querying its version.
$ java -version openjdk version "11.0.8" 2020-07-14 LTS OpenJDK Runtime Environment 18.9 (build 11.0.8+10-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode, sharing)
Download Gradle Source File and Extract It
On this tutorial we will be using binnary Gradle version 6.4. We will use user home directory to hold the binnary file. To download it, we will use wget command line, as shown below :
$ wget https://downloads.gradle-dn.com/distributions/gradle-6.4.1-bin.zip
Output :
ramans@otodiginet:~$ wget https://downloads.gradle-dn.com/distributions/gradle-6.4.1-bin.zip --2020-07-01 17:59:10-- https://downloads.gradle-dn.com/distributions/gradle-6.4.1-bin.zip Resolving downloads.gradle-dn.com (downloads.gradle-dn.com)... 104.17.159.20, 104.17.160.20, 2606:4700::6811:a014, ... Connecting to downloads.gradle-dn.com (downloads.gradle-dn.com)|104.17.159.20|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 102375999 (98M) [application/zip] Saving to: ‘gradle-6.4.1-bin.zip’ gradle-6.4.1-bin.zip 100%[=====================================>] 97.63M 58.1KB/s in 25m 13s 2020-07-01 18:24:26 (66.1 KB/s) - ‘gradle-6.4.1-bin.zip’ saved [102375999/102375999]
Once the download is completed, then we will extract it by using unzip command line and place the fils to /opt/gradle directory.
$ sudo mkdir /opt/gradle $ sudo unzip -d /opt/gradle /home/ramans/gradle-6.4.1-bin.zip
Output is shown below :
ramans@otodiginet:~$ sudo mkdir /opt/gradle [sudo] password for ramans: amans@otodiginet:~$ sudo unzip -d /opt/gradle /home/ramans/gradle-6.4.1-bin.zip Archive: /home/ramans/gradle-6.4.1-bin.zip creating: /opt/gradle/gradle-6.4.1/ inflating: /opt/gradle/gradle-6.4.1/README inflating: /opt/gradle/gradle-6.4.1/LICENSE
The file structures of Gradle version 6.4.1 is as shown below :
ramans@otodiginet:~$ cd /opt/gradle/ ramans@otodiginet:/opt/gradle$ ls -ltr total 4 drwxr-xr-x 5 root root 4096 Feb 1 1980 gradle-6.4.1 ramans@otodiginet:/opt/gradle$ ls -ltr /opt/gradle/gradle-6.4.1/ total 44 -rw-r--r-- 1 root root 976 Feb 1 1980 README -rw-r--r-- 1 root root 803 Feb 1 1980 NOTICE -rw-r--r-- 1 root root 23606 Feb 1 1980 LICENSE drwxr-xr-x 3 root root 4096 Feb 1 1980 lib drwxr-xr-x 2 root root 4096 Feb 1 1980 init.d drwxr-xr-x 2 root root 4096 Feb 1 1980 bin
Setting up Gradle Environment Variables
On this stage, we will set up the the environments variable of Gradle. We will to add Gradle bin directory to the system PATH
environment variable. For this purpose we will use vi text editor and make a file.
$ sudo vi /etc/profile.d/gradle.sh export GRADLE_HOME=/opt/gradle/gradle-6.4.1 export PATH=${GRADLE_HOME}/bin:${PATH}
Then we will make it to be an executable file, by changing its mode.
$ sudo chmod +x /etc/profile.d/gradle.sh
Then we will load it to the environment variables in the current shell session using the source command:
$ source /etc/profile.d/gradle.sh
Verifying Gradle Installation
After loading Gradle environment variables, then we will verify the Gradle installation by querying its version. To do this task, we will submit the command line :
$ gradle –v
Output :
ramans@otodiginet:/etc/profile.d$ gradle --v Welcome to Gradle 6.4.1! Here are the highlights of this release: - Support for building, testing and running Java Modules - Precompiled script plugins for Groovy DSL - Single dependency lock file per project For more details see https://docs.gradle.org/6.4.1/release-notes.html ------------------------------------------------------------ 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 (Ubuntu 11.0.7+10-post-Ubuntu-3ubuntu1) OS: Linux 5.4.0-39-generic amd64
Conclusion
On this short article, we have learnt how to install Gradle on Ubuntu 20.04 LTS operting system. I hope this article will be helpful.