How to Install Gradle Build Tool on Ubuntu 18.04 LTS

Gradle is a free and open-source build tool primarily used for Java projects. Gradle helps you to automate, build and deliver software efficiently. Gradle uses Groovy object-oriented programming language instead of XML to define the project configurations. Gradle also supports many popular IDE platforms, such as Android Studio, Eclipse, IDEA, and NetBeans.

In this tutorial, we will show you how to install the Gradle Build Tool on Ubuntu 18.04 LTS.

Requirements

  • A server running Ubuntu 18.04.
  • A root password is set up to your server.

Getting Started

Before starting, you will need to update your system with the latest version. You can do this by running the following command:

apt-get update -y
apt-get upgrade -y

Once your server is updated, restart your server to apply the changes.

Next, install other required packages with the following command:

apt-get install wget unzip -y

Install Java

Gradle needs Java to be installed on your system. You can install the latest version of Java by running the following command:

apt-get install default-jdk -y

After installing Java, you can verify the Java with the following command:

java -version

You should see the following output:

openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)

Install Gradle from PPA Repository

In this section, we will learn how to install Gradle from PPA Repository.

First, install all the required packages with the following command:

apt-get install apt-transport-https dirmngr wget software-properties-common -y

Next, download and import GPG key with the following command:

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D7CC6F019D06AF36

You should see the following output:

Executing: /tmp/apt-key-gpghome.XFiNpS59rU/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys D7CC6F019D06AF36
gpg: key D7CC6F019D06AF36: public key "Launchpad PPA for Cheng-Wei Chien" imported
gpg: Total number processed: 1
gpg:               imported: 1

Next, add the PPA repository with the following command:

add-apt-repository ppa:cwchien/gradle

Once the repository is added, update the repository and install Gradle by running the following commands:

apt-get update -y
apt-get install gradle -y

After installing Gradle, you can verify the Gradle installation with the following command:

gradle -v

You should get the following output:

Welcome to Gradle 5.6.3!

Here are the highlights of this release:
 - Incremental Groovy compilation
 - Groovy compile avoidance
 - Test fixtures for Java projects
 - Manage plugin versions via settings script

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


------------------------------------------------------------
Gradle 5.6.3
------------------------------------------------------------

Build time:   2019-10-18 00:28:36 UTC
Revision:     bd168bbf5d152c479186a897f2cea494b7875d13

Kotlin:       1.3.41
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          11.0.4 (Ubuntu 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OS:           Linux 4.15.0-20-generic amd64

Install Gradle from Source

In this section, we will learn how to install Gradle from Source.

Download Gradle

First, change the directory to /opt and download the latest version of Gradle with the following command:

cd /opt/
wget https://services.gradle.org/distributions/gradle-5.6.4-bin.zip

Once downloaded, unzip the downloaded file with the following command:

unzip gradle-5.6.4-bin.zip

You can verify the extracted directory with the following command:

ls /opt/gradle-5.6.4

Output:

LICENSE  NOTICE  bin  getting-started.html  init.d  lib  media

Configure Environment Variables

Next, you will need to set up environment variables to use Gradle. TO do so, create a new file inside /etc/profile.d directory:

nano /etc/profile.d/gradle.sh

Add the following lines:

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

Save and close the file then make the file executable with the following command:

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

Next, load the environment variables with the following command:

source /etc/profile.d/gradle.sh

Verify Installation

Gradle is now installed, it's time to verify whether Gradle is installed or not.

You can verify the Gradle installation with the following command:

gradle -v

You should get the following output:

Welcome to Gradle 5.6.4!

Here are the highlights of this release:
 - Incremental Groovy compilation
 - Groovy compile avoidance
 - Test fixtures for Java projects
 - Manage plugin versions via settings script

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


------------------------------------------------------------
Gradle 5.6.4
------------------------------------------------------------

Build time:   2019-11-01 20:42:00 UTC
Revision:     dd870424f9bd8e195d614dc14bb140f43c22da98

Kotlin:       1.3.41
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          11.0.4 (Ubuntu 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OS:           Linux 4.15.0-65-generic amd64

Conclusion

Congratulations! you have successfully installed Gradle on Ubuntu 18.04 server. You can now start building Java projects with Gradle. Feel free to ask me if you have any questions.

Share this page:

Suggested articles

2 Comment(s)

Add comment

Comments

By: anonymous at: 2020-06-02 16:22:04

gpg: no valid OpenPGP data found.

By: Mimi at: 2020-06-30 02:51:44

Appreciate for the guidelines on Gradle installation.it worked perfectly. Kudos!