How To Install Gradle on Ubuntu 20.04 / Ubuntu 18.04 & Linux Mint 20/19

Gradle is an open-source build automation tool used for Java, Groovy, and Scala development. It builds upon the concepts of Apache Ant and Apache Maven. Unlike Apache Maven which uses XML for declaring project configurations, Gradle uses Groovy, a dynamic, object-oriented programming language to define the project configurations.
In this post, we will install Gradle on Ubuntu 20.04 / Ubuntu 18.04 & Linux Mint 20 / Linux Mint 19.
Install Gradle on Ubuntu / Linux Mint
Install JDK / JRE
Gradle’s only requirement is Java JDK or JRE version 8 or above to be installed.
Update the repository index.
sudo apt update
If you prefer Oracle Java JDK over OpenJDK then follow the post about installation of Oracle Java on Ubuntu 20.04 / Ubuntu 18.04 & Linux Mint 20 / Linux Mint 19.
Here, I will go with OpenJDK 11.
Install the OpenJDK package by using the apt
command.
sudo apt install -y default-jdk-headless
Verify the Java installation by executing the following command.
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)
Install other supported packages.
sudo apt install -y wget unzip
Install Gradle
Download the latest version of the Gradle (V6.3) from the official site. Download the Gradle Binary-only zip file.
OR
Use the below command in the terminal to download the Gradle (v6.5.1) package.
cd /tmp wget https://services.gradle.org/distributions/gradle-6.5.1-bin.zip
Extract zipped package using unzip
command.
unzip gradle-*.zip
Move the content to /opt/gradle
directory.
sudo mkdir /opt/gradle sudo cp -pr gradle-*/* /opt/gradle
Verify the moved files by listing the /opt/gradle/
directory.
ls /opt/gradle/
Output:
bin init.d lib LICENSE NOTICE README
Setup Environment Variable
We will now configure the PATH environment variable to include the Gradle’s bin directory. To do that, create a new file named gradle.sh
inside of the /etc/profile.d/
directory.
echo "export PATH=/opt/gradle/bin:${PATH}" | sudo tee /etc/profile.d/gradle.sh
Make the script executable by using the chmod
command.
sudo chmod +x /etc/profile.d/gradle.sh
Load the environment variables for the current session by using the following command.
source /etc/profile.d/gradle.sh
Verify Gradle installation
To validate the Gradle installation, use the below command.
gradle -v
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
Conclusion
That’s All. You have successfully installed Gradle on Ubuntu 20.04 / Ubuntu 18.04 & Linux Mint 20 / Linux Mint 19. You can go to the official Gradle Documentation page to learn how to get started with Gradle.