Jul 12, 2023 4 min read

How to Install Gradle on Ubuntu 20.04

Install Gradle on Ubuntu 20.04 with our step-by-step tutorial. It is an open-source build automation tool widely used in software development.

Install Gradle on Ubuntu 20.04
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install Gradle on Ubuntu 20.04, let’s briefly understand - What is Gradle?

Gradle is a powerful open-source build automation tool widely used in software development. It simplifies and automates the build process, managing dependencies and compiling source code efficiently. With its flexibility and scalability, Gradle supports various programming languages and frameworks, making it a preferred choice for developers.

Its plugin ecosystem enables easy integration with popular tools, enhancing productivity and enabling smooth collaboration in projects. By optimizing the build process, Gradle boosts development speed and enhances overall project efficiency, making it an indispensable tool for modern software development.

In this tutorial, you will install Gradle on Ubuntu 20.04. We will also address a few FAQs on how to install Gradle on Ubuntu 20.04.

Advantages of Gradle

  1. Efficient Build Automation: Gradle simplifies and automates the build process, accelerating development and reducing manual effort.
  2. Dependency Management: Gradle handles dependencies effortlessly, ensuring smooth integration of libraries and components into your project.
  3. Multi-Language Support: Gradle supports a wide range of programming languages and frameworks, offering flexibility for diverse development needs.
  4. Extensive Plugin Ecosystem: Gradle's rich plugin ecosystem allows seamless integration with popular tools, enhancing productivity and extending functionality.
  5. Scalability and Performance: Gradle's optimized build process delivers fast and efficient builds, enabling efficient scaling for projects of any size.

Prerequisites to Install Gradle on Ubuntu 20.04

  • Login as root user with the sudo privileges.

Step 1 – Install the OpenJDK

1) Gradle needs installation of Java SE 8 or later on the machine. So, enter the below commands to install OpenJDK 11:

sudo apt update
sudo apt install openjdk-11-jdk

2) After that, verify the Java installation by printing the Java-version:

java -version

You will see the below result:

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)

Step 2 - Download Gradle

1) Here, the latest version of Gradle is 6.5.1. Therefore, check for the Gradle releases page, for a newer version if available. Also, download the Gradle binary-only zip file in the /tmp directory. Use the below wget command:

VERSION=6.5.1

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

2) After, completing the download. Now, unzip the file in the /opt/gradle directory using the following command:

sudo unzip -d /opt/gradle /tmp/gradle-${VERSION}-bin.zip
⚠️
If you are getting an error as sudo: unzip: command not found. You will install the unzip-package with sudo apt install unzip.

3) Now, to have more control over Gradle versions and updates. You will create a symbolic link namely, latest. It points it to the Gradle installation directory:

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

4) After upgrading the Gradle, unpack the newer-version and change the symlink to point to it.

Step 3 - Set up the Environment Variables

1) You will now add the Gradle bin directory to the system PATH environment variable. For this, open your text editor. Further, create a new file as gradle.sh inside the /etc/profile.d/ directory:

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

2) Also, paste the below configuration:

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

3) Then, save and close the file. This script will get sourced at shell startup. So, make the script executable using the following command:

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

4) Next, load the environment variables in the current shell session. You will use the source command:

source /etc/profile.d/gradle.sh

Step 4 - Verify the Gradle installation

1) You will now validate that Gradle installation properly. Use the gradle -v command, that will display the Gradle-version:

gradle -v

You will then see the below output:

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

So, the installation of latest version of the Gradle is complete. You can start using it now.

FAQs to Install Gradle on Ubuntu 20.04

Can I use a different version of Gradle?

Yes, you can install a different version of Gradle by replacing {version} in the download URL with the desired version number.

How do I update Gradle to the latest version?

To update Gradle to the latest version, repeat the installation steps using the updated download URL for the new version.

How can I uninstall Gradle from Ubuntu 20.04?

To uninstall Gradle, delete the Gradle installation directory (/opt/gradle) and remove the environment variable entry from ~/.bashrc or ~/.profile.

Can I install Gradle using a package manager on Ubuntu?

Yes, Gradle can be installed using a package manager like SDKMAN or Snap. Refer to their documentation for installation instructions.

What are the system requirements for installing Gradle on Ubuntu 20.04?

Gradle requires Java Development Kit (JDK) to be installed. Make sure you have JDK installed before proceeding with Gradle installation.

How can I configure Gradle for my project on Ubuntu 20.04?

Gradle projects are configured using build.gradle files. You can create or modify the build.gradle file in your project's root directory to configure dependencies, tasks, and other settings.

Conclusion

We hope this detailed tutorial helped you install Gradle on Ubuntu 20.04. To learn more about Gradle installation, check out the official Gradle documentation.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.