In this tutorial, we will show you how to install Gradle on Ubuntu 20.04 LTS. For those of you who didn’t know, Gradle is a modern build automation tool that allows developers to efficiently manage their projects. Unlike its predecessors, such as Apache Maven and Apache Ant, Gradle offers a more flexible and declarative approach to building projects. It leverages Groovy-based domain-specific language (DSL) for its build scripts, making it easy to write and maintain complex build configurations. With features like incremental builds, dependency management, and multi-project support, Gradle has become the preferred choice for many Java developers.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and, most importantly, host your site on your own VPS. The installation is quite simple and assumes you are running in the root account. If not, you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Gradle on the Ubuntu 20.04 LTS (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
Prerequisites
- A server running one of the following operating systems: Ubuntu 20.04, 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Gradle on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Installing Java.
Gradle requires Java to be installed on your server. So first of all, Make sure you have Java installed on your system:
sudo add-apt-repository ppa:linuxuprising/java
Once the repository is added, proceed to install Java on Ubuntu Linux:
sudo apt update sudo apt install oracle-java14-installer
Then, type below to confirm the Java version:
$ java --version
Step 3. Installing Gradle on Ubuntu 20.04.
Run the commands to download the latest Gradle distribution release binary file from its official download page. At the time of writing this tutorial:
wget https://github.com/gradle/gradle/archive/refs/tags/v8.8.0.zip -P /tmp
Then, extract the downloaded archive using the following command:
sudo unzip -d /opt/gradle /tmp/gradle-*.zip ls /opt/gradle/gradle-*
Step 4. Setup Environment Variables.
To configure the PATH environment variable to include the Gradle bin directory. create a new file named gradle.sh
inside the /etc/profile.d/
directory as below:
sudo nano /etc/profile.d/gradle.sh
Paste the following configuration:
export GRADLE_HOME=/opt/gradle export PATH=${GRADLE_HOME}/bin:${PATH}
Finally, load the environment variables using the following command:
source /etc/profile.d/gradle.sh
Step 5. Verify the Gradle installation.
Finally, to verify if Gradle is installed properly use the gradle -v
a command that will display the Gradle version:
$ gradle -v Welcome to Gradle 6.5! Here are the highlights of this release: - Experimental file-system watching - Improved version ordering - New samples For more details see https://docs.gradle.org/6.5/release-notes.html ------------------------------------------------------------ Gradle 6.5 ------------------------------------------------------------ Build time: 2020-07-14 15:46:21 UTC Revision: a27f41e4ae5e8agamad6d86d7b3mona4 Kotlin: 1.3.72 Groovy: 2.5.11 Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019 JVM: 12.0.7 (Ubuntu 11.0.7+10-post-Ubuntu-3ubuntu1) OS: Linux 5.4.0-33-generic amd64
Congratulations! You have successfully installed Gradle. Thanks for using this tutorial for installing Gradle on Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you to check the official Gradle website.