How To Install Gradle on Debian 10 / Debian 9
Gradle is an open-source build automation tool used for compiling, running, testing applications and much more. Build scripts are written in Groovy or Kotlin. It uses Apache Ant and Apache Maven’s build concepts for automating the build.
Initially, Gradle was used mainly for Java, Groovy, and Scala development and deployment. But, it is now used for Android, Kotlin, and other popular technologies.
In this post, we will see how to install Gradle on Debian 10 & Debian 9.
Install JDK/JRE
Gradle requires Java JDK or JRE version 8 or above to be available on the system.
If you prefer Oracle Java JDK, then:
READ: How To Install Oracle Java on Debian 10 / Debian 9
Here, I will use OpenJDK 8 for this tutorial. You are free to use any version above OpenJDK 8.
Update the repository index.
sudo apt update
Install the OpenJDK package using the apt command.
sudo apt install -y openjdk-8-jdk-headless
OR
sudo apt install -y default-jdk
Verify the Java installation with the following command.
java -version
Output: openjdk version "1.8.0_242" OpenJDK Runtime Environment (build 1.8.0_242-8u242-b08-1~deb9u1-b08) OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
Install other required packages.
sudo apt install -y wget unzip
Install Gradle
Download the latest version of the Gradle package (v6.3) from the official site. We will use the Gradle Binary-only zip file for the installation.
OR
Use the below command in terminal to download Gradle (version 6.3).
cd /tmp
wget https://services.gradle.org/distributions/gradle-6.3-bin.zip
Unzip the Gradle package using unzip command and move unzipped files to /opt/gradle directory.
unzip gradle-*.zip
sudo mkdir /opt/gradle
sudo cp -pr gradle-*/* /opt/gradle
Verify the unzipped files by listing the /opt/gradle/ directory.
ls /opt/gradle/
Output: LICENSE NOTICE bin getting-started.html init.d lib media
Setup environment variables
Now, we will configure the PATH environment variable to include the Gradle’s bin (executable) directory.
To do that, create a new file called gradle.sh inside the /etc/profile.d/ directory to export the PATH variable.
echo "export PATH=/opt/gradle/bin:${PATH}" | sudo tee /etc/profile.d/gradle.sh
Make the script executable 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.3! Here are the highlights of this release: - Java 14 support - Improved error messages for unexpected failures For more details see https://docs.gradle.org/6.3/release-notes.html ------------------------------------------------------------ Gradle 6.3 ------------------------------------------------------------ Build time: 2020-03-24 19:52:07 UTC Revision: bacd40b727b0130eeac8855ae3f9fd9a0b207c60 Kotlin: 1.3.70 Groovy: 2.5.10 Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019 JVM: 1.8.0_242 (Oracle Corporation 25.242-b08) OS: Linux 4.9.0-11-amd64 amd64
Conclusion
That’s All. You have successfully installed Gradle on Debian 10 / Debian 9. You can go to the official Gradle documentation page to get started with Gradle.