How to Install Gradle on Linux

Gradle is a popular build automation tool used mainly for Java projects, though it supports many other languages and platforms. This guide will walk you through the steps to install Gradle on a Linux system, set up the necessary environment variables, and verify the installation.

Step 1: Install Java Development Kit (JDK)

Gradle requires a Java Development Kit (JDK) to run. Make sure you have JDK installed on your system. If not, install it using the following commands:

For Debian-based distributions (Ubuntu, etc.)

sudo apt update
sudo apt install openjdk-11-jdk

For Red Hat-based distributions (Fedora, CentOS, etc.)

sudo dnf install java-11-openjdk-devel

Step 2: Download the Gradle Binary

  1. Visit the official Gradle releases page and copy the download link for the latest binary release.
  2. Download the Gradle binary using wget or curl. Replace GRADLE_VERSION with the actual version number you want to install (e.g., 7.4.2).

Step 3: Extract the Gradle Binary

  1. Create a directory for Gradle.
sudo mkdir /opt/gradle
  1. Extract the downloaded ZIP file to the /opt/gradle directory.
sudo unzip -d /opt/gradle
  1. Create a symbolic link to the extracted directory for easier access.
sudo ln -s /opt/gradle/gradle-GRADLE_VERSION /opt/gradle/latest

Step 4: Set Up Environment Variables

  1. Open your shell profile file in a text editor. This might be .bashrc, .zshrc, or another file, depending on your shell. For example, if you use Bash:
nano ~/.bashrc
  1. Add the following lines to set the GRADLE_HOME environment variable and update the PATH:
export GRADLE_HOME=/opt/gradle/latest
  1. Save the file and exit the text editor.
  2. Reload the shell configuration by running:
source ~/.bashrc

Step 5: Verify the Installation

  1. Check the Gradle version to verify that it has been installed correctly:
gradle -v
  1. You should see an output that displays the Gradle version and other related information, indicating that Gradle is successfully installed. The output should look something like this:
Gradle 7.x.x

Build time:   yyyy-MM-dd HH:mm:ss UTC
Revision:     xxxxxxxxxxxxxxxxxxxxxx

Kotlin:       1.x.x
Groovy:       3.x.x
Ant:          Apache Ant(x.x.x)
JVM:          x.x.x (Oracle Corporation x.x.x)
OS:           Linux x.x.x-xx-generic amd64


You have now successfully installed Gradle on your Linux system. With Gradle installed, you can start building and managing your projects more efficiently. For more information on using Gradle, check out the official Gradle documentation.

If you encounter any issues or have any questions, feel free to ask in the comments below. Happy building!