How To

Install Gradle on Ubuntu 18.04: Set Up OpenJDK and Environment

Gradle is a powerful open-source build automation tool used primarily for Java, Kotlin, Groovy, and Android projects. It combines the flexibility of Apache Ant with the dependency management of Apache Maven, but replaces XML configuration files with Groovy or Kotlin DSL scripts, which are far more readable and expressive.

Gradle supports incremental builds, build caching, and large multi-project configurations. It is also the default build system for Android development in Android Studio.

This guide covers how to install Gradle on Ubuntu 18.04 by downloading the binary distribution and configuring the PATH environment variable. The same steps apply to Ubuntu 16.04, Linux Mint, and Elementary OS.

<strong>Prerequisite:</strong>&nbsp;You need sudo access.

Install Gradle on Ubuntu: Install OpenJDK 8 and Download Gradle

Install OpenJDK 8. Gradle requires Java JDK or JRE version 7 or later. OpenJDK 8 is a widely supported, long-term stable choice:

bashsudo apt updatesudo apt install openjdk-8-jdk

Verify the Java installation:

bashjava -version

The output should show openjdk version "1.8.0_x". If multiple Java versions are installed, use sudo update-alternatives --config java to select the active one.

Download the Gradle binary-only zip. Check the Gradle releases page for the latest version before running this command. The -bin.zip package contains only the runtime binaries, not the source code or documentation, which keeps the download smaller:

bashwget https://services.gradle.org/distributions/gradle-5.0-bin.zip -P /tmp

Extract Gradle to /opt/. The /opt/ directory is the standard location under the Linux Filesystem Hierarchy Standard for optional software installed outside the package manager:

bashsudo unzip -d /opt/gradle /tmp/gradle-*.zip

Confirm the extraction completed correctly:

bashls /opt/gradle/gradle-5.0

You should see the bin/lib/, and init.d/ directories in the output.

Configure PATH Environment Variables and Verify the Gradle Install

Create a new profile script in /etc/profile.d/ to add Gradle to the system-wide PATH. Scripts in this directory are automatically sourced at shell login for all users, which makes it the right place for system-wide environment settings:

bashsudo nano /etc/profile.d/gradle.sh

Add the following content:

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

GRADLE_HOME points to the Gradle installation directory. Prepending it to PATH ensures the gradle command is found before any other version on the system.

Make the script executable and load the environment variables for the current session:

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

Verify the installation:

bashgradle -v

The output prints the Gradle version alongside the Kotlin DSL version, Groovy version, and JVM details. A clean output confirms the setup is working correctly.

How Gradle Works and What to Know Before Your First Build

Gradle builds are defined in a build.gradle file (Groovy DSL) or build.gradle.kts (Kotlin DSL) at the project root. The file declares pluginsdependencies, and tasks that Gradle resolves and executes in the correct order.

A few things that help when getting started with Gradle:

  • Gradle Daemon: Gradle runs a long-lived background process to keep the JVM warm between builds. This dramatically cuts startup time during iterative development
  • Gradle Wrapper: most real-world projects include a gradlew script that downloads the exact Gradle version the project requires. This ensures consistent builds across machines without relying on a global install
  • Build cache: Gradle caches task outputs and reuses them when inputs have not changed. For large projects, this significantly reduces build times on repeated runs
  • Upgrading Gradle: download the new version to /opt/gradle/ and update the GRADLE_HOME value in /etc/profile.d/gradle.sh

Gradle 5.0 is now installed on your Ubuntu 18.04 system. Read the official Gradle documentation to learn how to write build files, manage dependencies, and run your first build. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

Install phpMyAdmin on Ubuntu 18.04 with Apache: Setup Guide

phpMyAdmin is a free, open-source PHP application that provides a browser-based interface for managing MySQL and…

34 minutes ago

Install Zabbix on Ubuntu 18.04: Server Setup with MySQL Backend

Zabbix is a mature open-source infrastructure monitoring platform that collects metrics from network devices, servers, virtual…

39 minutes ago

Install TeamViewer on Ubuntu 18.04: Download the .deb and Set Up

TeamViewer is a proprietary cross-platform remote access application for remote control, desktop sharing, file transfer, and online meetings. It is one of the most widely used remote support tools in the world, available for Windows, macOS, Linux, iOS, and Android. TeamViewer is not included in the Ubuntu repositories because it is proprietary software. This guide covers how to install TeamViewer on Ubuntu 18.04 using the official .deb package. The same steps apply to Ubuntu 16.04, Debian, Linux Mint, and Elementary OS. <strong>Prerequisite:</strong>&nbsp;You&nbsp;need&nbsp;sudo&nbsp;access. Install TeamViewer on Ubuntu: Download the .deb Package Download the official TeamViewer .deb package. The _amd64.deb suffix indicates this package is for 64-bit x86-64 systems. For ARM-based machines, download the appropriate package from the TeamViewer Linux downloads page: bashwget https://download.teamviewer.com/download/linux/teamviewer_amd64.deb Install the package using apt. The ./ prefix tells apt this is a local file path, not a package name from the repositories:…

49 minutes ago

Install Nagios Core on Ubuntu 18.04: Build from Source Guide

Nagios is one of the most widely used open-source infrastructure monitoring systems in the world. It…

54 minutes ago

Install Laravel on Ubuntu 18.04 with Composer: Setup Guide

Laravel is an open-source PHP web application framework built around an expressive, developer-friendly syntax. It is…

19 hours ago

Install Kodi on Ubuntu 18.04: Add the Official PPA and Set Up

Kodi (formerly XBMC, short for Xbox Media Center) is a free, open-source, cross-platform media player and…

19 hours ago