Gradle is a powerful open-source build automation tool that is widely used for building Java projects, as well as projects in other languages such as C/C++ and JavaScript. It provides developers with a flexible and efficient way to automate the build, test, and deployment processes. In this tutorial, we will guide you through the process of installing Gradle on Ubuntu 22.04, enabling you to leverage its capabilities for your software development projects.

Prerequisites

Before we begin, please ensure that you have the following:

  • A server running Ubuntu 22.04 (Jammy Jellyfish)
  • Root access or superuser privileges on your server

Step 1: Update Your System

The first step is to update your system to ensure that you have the latest packages installed. Open a terminal and run the following commands:

sudo apt update -y
sudo apt upgrade -y

These commands will update all the system packages to their latest versions. Additionally, we will install some required packages by running the following command:

sudo apt install wget unzip -y

Once the update and package installation are complete, you can proceed to the next step.

Step 2: Install Java JDK

Gradle is built on Java, so we need to install the Java Development Kit (JDK) on our system. We will install the default version of JDK available in the Ubuntu repositories. Run the following command to install it:

sudo apt install default-jdk -y

After the installation is complete, you can verify the Java installation by running the following command:

java -version

You should see the output displaying the Java version installed on your system.

Step 3: Install Gradle Using Snap

One of the easiest ways to install Gradle on Ubuntu is by using the Snap package manager. Snap allows you to install software packages that are bundled with their dependencies, ensuring easy installation and updates. To install Gradle using Snap, run the following commands:

sudo apt install snapd -y
sudo snap install gradle --classic

Once the installation is complete, you can verify the Gradle installation by running the following command:

gradle -v

This command will display the Gradle version and other relevant information.

Step 4: Install Gradle from Source

If you prefer to install Gradle from the source, you can follow these steps:

  1. Change the directory to /opt by running the command cd /opt.
  2. Download the latest version of Gradle using the wget command. For example, to download Gradle version 7.6, use the following command:
   wget https://downloads.gradle-dn.com/distributions/gradle-7.6-bin.zip
  1. Extract the downloaded file using the unzip command. For example:
   unzip gradle-7.6-bin.zip
  1. Rename the extracted directory using the mv command. For example:
   mv gradle-7.6 gradle
  1. Verify the extracted directory by running the following command:
   ls /opt/gradle

You should see the contents of the Gradle directory.

Step 5: Configure Gradle Environment Variables

To use Gradle, we need to set up the environment variables. Let’s create a file to define these variables. Run the following command to open a new file:

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

Add the following lines to the file:

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

Save and close the file. Set the executable permission on the script by running the following command:

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

Finally, load the environment variables by running the following command:

source /etc/profile.d/gradle.sh

Step 6: Verify the Gradle Installation

To ensure that Gradle is installed correctly, run the following command:

gradle -v

You should see the Gradle version and other details displayed in the output.

Congratulations! You have successfully installed Gradle on your Ubuntu 22.04 server. You can now leverage the power of Gradle to automate your build processes and streamline your software development workflow.

If you have any questions or need further assistance, feel free to reach out to our support team at Shape.host. Our team of experts is always ready to help you with your hosting needs.