Gradle is a free and open-source build automation tool used for developing different applications. It uses Groovy to define project configurations. Gradle is compatible with Java, Javascript, and C/C++. It helps you to manage required libraries, deployment, testing, and notifications of the application in different platforms. Gradle is very popular due to its simplicity, ease of use, and prebuilt functionality.

In this post, we will show you how to install Gradle on Debian 11.

Step 1 – Install Java JDK

Gradle is a Java-based application, so Java JDK must be installed on your server. If not installed you can install it by running the following command:

apt-get update -y
apt-get install default-jdk -y

Once Java JDK is installed, verify the Java installation using the command given below:

java --version

You will get the following output:

openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Debian-1deb10u1, mixed mode, sharing)

Step 2 – Install Gradle on Debian 11

First, install the required dependencies using the following command:

apt-get install curl unzip -y

Next, download the latest version of Gradle using the following command:

curl -O https://downloads.gradle-dn.com/distributions/gradle-7.3.2-bin.zip

Once the download is completed, unzip the downloaded file with the following command:

unzip gradle-7.3.2-bin.zip

Next, move the extracted directory to /opt with the following command:

mv gradle-7.3.2 /opt/gradle

Now, run the following command to list all files and directories inside /opt/gradle directory:

ls /opt/gradle/

You should see the following output:

bin  init.d  lib  LICENSE  NOTICE  README

Step 3 – Set up Environment Variable

Next, you will need to create an environment variable for Gradle. You can create it by running the following command:

echo "export PATH=/opt/gradle/bin:${PATH}" | tee /etc/profile.d/gradle.sh

Next, set executable permissions to the gradle.sh file:

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

Next, activate the environment variable using the following command:

source /etc/profile.d/gradle.sh

Step 4 – Verify the Gradle Installation

At this point, Gradle is installed in your system. You can now verify the Gradle installation using the following command:

gradle -v

You should see the following output:

Welcome to Gradle 7.3.2!


Here are the highlights of this release:
 - Easily declare new test suites in Java projects
 - Support for Java 17
 - Support for Scala 3

For more details see https://docs.gradle.org/7.3.2/release-notes.html


------------------------------------------------------------
Gradle 7.3.2
------------------------------------------------------------

Build time:   2021-12-15 11:22:31 UTC
Revision:     26c186eb63b2b02e68d83b0dbc6ec69ab118653a

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.13 (Debian 11.0.13+8-post-Debian-1deb11u1)
OS:           Linux 5.10.0-8-amd64 amd64

Step 5 – Create a Project with Gradle

In this section, we will show you how to create a sample project with Gradle.

First, create a directory for your project:

mkdir project

Next, navigate to the project directory and initialize the project with the following command:

cd project
gradle init

You will be asked to select the type of project to generate:

Starting a Gradle Daemon (subsequent builds will be faster)

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 1

Type 1 and press the Enter key. You will be asked to select the build script:

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 1

Type 1 and press Enter key. Once the project has been built successfully, you will get the following output:

Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] 
Project name (default: project): 

> Task :init
Get more help with your project: Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.3.2/samples

BUILD SUCCESSFUL in 31s
2 actionable tasks: 2 executed

You can list your project files using the following command:

ls

You should see the following output:

build.gradle  gradle  gradlew  gradlew.bat  settings.gradle

Conclusion

Congratulations! You have successfully installed Gradle on Debian 11. You can now start deploying your application using Gradle. Try it on dedicated hosting from Atlantic.Net!