×



Gradle is a powerful tool that can be used to automate the compilation and execution of source code on various platforms. It was originally created by Johnson Markham in April 2012, but after he passed away from cancer it became active again under Google's ownership with help from many others who continue developing this great project today.

One of the main advantages of Gradle is its flexibility. It can be used to build both simple and complex projects, and it can be easily customized to suit the needs of each project.

Gradle also integrates well with other development tools. For example, it can be used to compile Java code, run unit tests, and create Javadoc documentation. Another advantage of Gradle is its speed. It can quickly build large projects without bogging down your computer’s CPU or memory.

From mobile apps to web applications, Gradle can be used to build just about any type of software. If you're looking for a build automation system that is both powerful and customizable, then Gradle is definitely worth considering.

Gradle is written in Java and uses Groovy as its scripting language. Groovy is a powerful JVM-based language that was designed for use with Java. If you're not familiar with Groovy, don't worry – Gradle can be used without knowing any of its features. However, if you want to take advantage of some of the more advanced features of Gradle, it's worth learning at least a little bit about Groovy.

Gradle is similar to Apache Maven, a popular build automation system for Java projects. 

Here at LinuxAPT, we shall look into how to install Gradle on Debian 10.


Key differences between Gradle and Maven includes:

  • Powerful dependency management – The dependency management tool allows you to quickly import external libraries into your project. By contrast, Apache Maven uses a central repository that contains thousands of commonly used libraries that have been submitted by the community. This makes it easier to share code between developers, but if you’re working on a smaller project then it may not be worth using this feature.
  • Easier script configuration – With Gradle you can configure each build task using a separate Groovy script file. You can also configure different tasks at the same time by adding additional scripts to a single file. Apache Maven uses a XML-based configuration file, which can be more difficult to manage if you have a large project.
  • More powerful plugin system – Gradle has a powerful plugin system that allows you to add custom tasks and plugins to your project. This can be useful for integrating with other development tools, or for automating common tasks. Apache Maven doesn’t have as many plugins available, and the ones that are available are not always as powerful as those in Gradle.


Steps to install and configure Gradle on Debian Linux system

1. Perform System Update

Gradle will compile code, so it's best to have an up-to-date system. You can update your Debian server using the following command:

$ sudo apt update && sudo apt upgrade -y

If you are not yet logged in as root, then you will be asked for your sudo password. Otherwise, the required packages will be automatically upgraded, and your system will be updated.


2. Install Java

If you plan to use Gradle in a Java project, then it’s best to install the JDK. The JDK (Java Development Kit) contains everything you need to compile and run java programs. The most recent version of the JDK available is OpenJDK 17.

But we will use the JDK 11 because it has long-term support and is the official reference implementation for Java SE. Also, some old library dependencies are not compatible with JDK 11.

You can install Oracle JDK 11 using this command:

$ sudo apt install openjdk-11-jdk -y

To check if you installed your JDK successfully, open a new terminal window and run the command below.

The -version command is a simple command that can run any program and shows the version for that particular program. For java, it will show the version of Java that you've installed on your machine. The result of this command depends on which Jave you have installed:

$ java -version

OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2deb10u1) means that the current OpenJDK version is 11.0.12.

OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2deb10u1, mixed mode, sharing) means that the VM is running in 64-bit mode and shares memory with other processes.


3. Configure Java 11

In order to use Gradle with Java 11, we need to configure our environment variables. We can do this by editing the /etc/environment file.

A variable is a named container for a value that can be changed. Here, we will set the JAVA_HOME environment variable to the path of our JDK installation.

First, run the command below to get a list of all the installed Java versions. The update-alternatives command is used to configure the system for choosing which terminal program to use. It can also be used to choose which Java version to use:

$ sudo update-alternatives --config java

You can see that OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java. We need to add this path to our environment variable in order for it to work properly.

Open the /etc/environment file in your favorite editor. This example uses nano:

$ sudo nano /etc/environment

Copy and paste the following line to the bottom of the file and save it. This sets the JAVA_HOME environment variable to the path of the Java 11 installation.

Notice that we will remove the trailing bin/java part of the path prior to adding it to our environment variables. This ensures that when Java is called, Gradle will use this version instead of calling OpenJDK 11 directly:

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

Save the file and close it. Run the following source command to reload your environment variables. You can also do this by logging out and logging back in.

$ source /etc/environment

Now, run the echo command to verify that it worked:

$ echo $JAVA_HOME

The output will be the path of the JDK installation. If you don't see this, then something went wrong! Check the /etc/environment file to make sure you added the correct line.


4. Install Gradle

Now that we have Java 11 configured, we can install Gradle. We'll be using the binary distribution for Gradle.

We can download the Gradle binaries directly from the Gradle website. The Gradle binaries are pre-built packages for Gradle that have already been built by the creators of Gradle.

Most people will use these binaries to install Gradle because it is much easier than building them yourself. The benefit of this is twofold: First, your machine doesn't have to build anything, which can take a long time. Second, the binaries are guaranteed to be compatible with your machine and Gradle versions.

The Gradle downloads page https://gradle.org/releases/ has different binaries for different operating systems. We'll be using the one for Linux.

Run the wget command below to download the Gradle binaries. https://services.gradle.org/distributions/gradle-6.3-bin.zip is the URL of the Gradle binaries. -P /tmp specifies the local directory to download the file to:

$ wget https://services.gradle.org/distributions/gradle-6.3-bin.zip -P /tmp

When the download is finished, we'll need to unzip it with the unzip command:

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

d is a flag that specifies the destination directory for the file contents. /opt/gradle is the local directory to extract Gradle to. ~/tmp/gradle-*.zip is an example of specifying the name of the files to unzip. This works because unzip by default unzips all files with .zip as their extension.

This will create a new directory at /opt/gradle/ called gradle-6.3. You can verify that this works by checking out its contents with the ls command:

$ ls /opt/gradle/gradle-*

The output will be a list of all the files in the directory, including the gradle-6.3 directory that we just created.

At this point, we have Gradle installed, but it isn't configured. We need to configure the path to the Gradle executable in our environment variables.

At this point, we have Gradle installed, but it isn't configured. We need to configure the PATH to the Gradle executable in our environment variables.

PATH is an environment variable that specifies a list of directories that the shell should search for executable files. This is useful because it allows us to have multiple versions of Gradle installed on our machine and be able to call them easily from the command line.

We can configure the path to the Gradle executable by setting the GRADLE_HOME environment variable. This variable will tell Gradle where to find its home directory.

The command below will create a new file named gradle.sh in the /etc/profile.d directory:

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

Paste the following code into the file, making sure to replace the path with the correct path on your machine:

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

Where:

export GRADLE_HOME=/opt/gradle/gradle-6.3 sets the GRADLE_HOME environment variable to /opt/gradle/gradle-6.3:

export PATH=${GRADLE_HOME}/bin:${PATH} sets the PATH environment variable to ${GRADLE_HOME}/bin:${PATH} The ${PATH} variable is important because it makes Gradle accessible from the command line.

Now we just need to save and exit by typing CTRL+X to save the file as a .sh file, hitting ENTER, and then typing Y and ENTER.

Next, run the sudo chmod +x /etc/profile.d/gradle.sh command to make the file executable. When you create a new file in the /etc/profile.d directory, it will not be executable by default. So we need to make the file executable so that our system can run it when we log in:

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

We can now load our changes by running the source command below. This will tell the current shell to use these environment variables so we can be sure Gradle is working:

source /etc/profile.d/gradle.sh

Finally, we can verify that everything is working by running the gradle command:

$ gradle -v

The output will show you the Gradle version that is currently installed. 


[Need help in fixing Linux System issues ? We can help you. ]



Conclusion

This article covers how to install Gradle on a Debian 10 machine. In fact, Gradle is an open-source tool for build automation Java, Groovy, and Scala development. It relies on the concepts of Ant and Maven to automate the building process.


How to Install gradle on Debian Using apt ?

Update apt database with apt using the following command:

$ sudo apt update

After updating apt database, We can install gradle using apt by running the following command:

$ sudo apt -y install gradle


How To Uninstall gradle on Ubuntu 21.10 ?

To uninstall only the gradle package we can use the following command:

$ sudo apt-get remove gradle

We can use the following command to remove gradle configurations, data and all of its dependencies, we can use the following command:

$ sudo apt-get -y autoremove --purge gradle

More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com