How to Install Gradle on Ubuntu Linux

This tutorial guides users on installing Gradle, an open-source build automation system, on Ubuntu 20.04 & 18.04. It begins with the installation of Java JDK, specifically OpenJDK 8. Subsequently, it details the steps to download and extract Gradle, followed by configuration of Ubuntu environment variables for Gradle’s usage.

This article explains how to install Gradle on Ubuntu Linux.

Gradle is an open-source build automation system that helps developers automate, build, and deliver software efficiently. Unlike its predecessors, it improves on Apache Ant and Apache Maven concepts and uses Groovy-style language instead of XML.

Installing the Gradle Build Tool on Ubuntu Linux is essential for developers who want to automate software applications’ build and delivery process. Gradle is an open-source build automation system that enables developers to build and deliver software more efficiently.

It improves on the concepts of Apache Ant and Apache Maven and uses Groovy-style language instead of XML, making it easier to work with. Gradle works seamlessly with many popular IDE platforms, such as Android Studio, Eclipse, IDEA, and NetBeans, and is widely used by developers worldwide.

By installing Gradle on Ubuntu Linux, developers can improve their productivity and streamline the software development process, making it faster and more efficient.

For more about Gradle, please visit its homepage.

Install Java JDK

Gradle needs Java JDK installed on Ubuntu. It requires Java JDK 7 and above. However, Java JDK 8 is much more stable and supported across many platforms. For this tutorial, we will install OpenJDK 8 on Ubuntu.

To install OpenJDK 8, run the commands below

sudo apt update
sudo apt install openjdk-8-jdk

After that, run the commands below to print out the installed version of Java.

java -version

You should see similar content as shown below:

openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.18.04.1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

Install Gradle

Now that OpenJDK 8 is installed, run the commands below to download Gradle version 4.10.2 in the /tmp. At the time of this writing, the version is 4.10.2

cd /tmp
wget https://services.gradle.org/distributions/gradle-4.10.2-bin.zip

After that, extract the content into the /opt directory.

sudo unzip -d /opt/gradle /tmp/gradle-*.zip

The grade should be extracted to the /opt/gradle/gradle-4.10.2 directory. You will want to keep the version separate so you can upgrade easily. In the future, you only need to create a symbolic link to the version folder to use that version.

Configure Ubuntu Environment Variables

Now that you’ve extracted Gradle content configure Ubuntu environment variables to use Gradle. You can run the commands below to create a new file called Gradle. sh in the /etc/profile.d directory.

sudo nano /etc/profile.d/gradle.sh

They copy and paste the lines below into the file and save.

export GRADLE_HOME=/opt/gradle/gradle-4.10.2
export PATH=${GRADLE_HOME}/bin:${PATH}

When you’re done, run the commands below to make the file executable.

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

You should be able to use Gradle on Ubuntu. To print out the Gradle version and info sheet, run the commands below

gradle -v

That should print out its info as shown below:

Welcome to Gradle 4.10.2!

Here are the highlights of this release:
------------------------------------------------------------
Gradle 4.10.2
------------------------------------------------------------

Build time:   2018-09-19 18:10:15 UTC
Revision:     b4d8d5d170bb4ba516e88d7fe5647e2323d791dd

Kotlin DSL:   1.0-rc-6
Kotlin:       1.2.61
Groovy:       2.4.15
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          1.8.0_181 (Oracle Corporation 25.181-b13)
OS:           Linux 4.15.0-36-generic amd64

Enjoy!

Conclusion:

This post showed you how to install Gradle on Ubuntu 20.04 | 18.04. If you find any error above, please comment in the form below and report.

Thanks,

You may also like the post below:

Richard Avatar

Comments

  1. In ubuntu 20.04 while running Android studio error could not install gradle distribution from ‘https://services.gradle.org/distributions/gradle-6.5.1-bin.zip’.

Leave a Reply

Your email address will not be published. Required fields are marked *