How to Install Gradle on Ubuntu 16.04

How to Install Gradle on Ubuntu 16.04

Ever wondered how to install Gradle on Ubuntu 16.04 for some much-needed automation when programming with Java? Here’s everything you need to know about it. 

Gradle is a general-purpose tool used for the automation of Java projects. Instead of using extensible markup language (XML) for scripting, this tool uses an object-oriented language called GDSL to define the project’s configuration. 

Before you can start using the automation tool, you should have an account with root access, and a Java development kit (JDK) installed on your computer. The installation steps for Java will be discussed in this article, followed by the instructions to install Gradle. 

In addition, before installing, run the following command on the Terminal to update the package index and install packages to the latest version:

$sudo apt update
$ sudo apt upgrade

Introduction to Gradle

Gradle is an open-source project built on the same philosophy as Ant and Maven. It uses the power and dependency management and conventions of Maven to evolve as an effective tool for building software. Furthermore, it can automate the various phases of software development, such as building, testing, publishing, and deployment. 

Gradle can also be used for creating Java projects and building tools for Android—among these other features:

  • It uses a domain-specific language (GDSL) for declaring the project configuration
  • It can be customized and extended in various ways
  • Fast and incremental executions via reusing outputs from the last executions and processing inputs only that are changed
  • It can also execute tasks in parallel
  • It provides support for a variety of languages and technologies

Tip: Gradle is supported by various tools such as Eclipse IDEA, NetBeans, and Android Studio.

Installation of Prerequisite Software for Gradle

Before proceeding with the installation, let’s first install the prerequisite software for Gradle. There is only one prerequisite for the tool (i.e., Java). To install Java, open the Terminal from the system menu and select Terminal. Then, type the following command to first update the repository:

$ sudo apt update

After that, run the following command to install the Java development kit (JDK):

$ sudo apt install openjdk-8-jdk

Once the JDK is installed, it can be verified via the following command:

$ java –version

You will see the version of the Java software displayed. If all goes well, you can proceed toward Gradle’s installation. Gradle can be installed in two ways: you can install the Gradle software from the ppa repository or manually via downloading from the website.

How to Install Gradle on Ubuntu from ppa repository

The Gradle software can be installed from the ppa repository by following the steps below.

Add repository

The first step is to add the ppa repository by running this command:

$ sudo add-apt-repository ppa:cwchien/gradle

Update your system

Now, update your system with the use of this command:

$ sudo apt update


Install Gradle

Now, you can install the Gradle software by running the following command on your Terminal:

$ sudo apt install gradle

Installing Gradle Manually via Website

We will now discuss the steps to install Gradle manually. We will download Gradle from the official website and then configure its environment variables to run the software.

Download Gradle

You can use the wget command to download Gradle by typing the following on the Terminal:

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

Unzip the Gradle Package

Once the Gradle software is downloaded, it can be extracted into the appropriate folder by using the unzip utility:

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


Now, check if the tool has been appropriately extracted by listing down the contents of the directory:

$ls

You should see the folder for Gradle in your current directory.

Setting up the environment variable

Now, we will set the environment variable PATH to execute Gradle binaries from any folder. Create a shell script gradle.sh and open it in your favorite editor. Both of these steps can be performed via the following command on the Terminal:

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

Note that the shell script should be created in the /etc/profile.d/ directory. Now, type the following lines in the gradle.sh file:

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


Now, change the permissions of the script file such that it can be executed. The permissions can be changed via the chmod command:

$ sudo chmod u+x  gradle.sh


Apply the gradle.sh changes (i.e., load the environment variables) by running the following command on the Terminal:

$ source /etc/profile.d/gradle.sh


Verify the installation of Gradle

At this point, we shall verify if Gradle has been installed properly on your system. Type the following command on your Terminal to do so:

$ gradle –v


You will see a welcome message and the version of Gradle displayed. 

In this article, we have discussed the methods to install Gradle. It is used for building Java projects. We also talked about the installation process for the prerequisite software and then the steps required to install and configure the Gradle. 

Lastly, the installation can be performed via the ppa repository or manually downloaded from the official website.

If this guide helped you, please share it.

Leave a Reply
Related Posts