---
title: How to Install Gradle on Ubuntu 24.04
url: https://docs.vultr.com/how-to-install-gradle-on-ubuntu-24-04
description: Learn how to install Gradle on Ubuntu 24.04 with step-by-step instructions. This guide covers multiple installation methods for this powerful build automation tool.
publish_date: 2025-01-31T05:53:54.708676Z
last_updated: 2026-09-09T23:28:42.756386Z
author: Vishwas Agrawal
header_image: https://assets.vultrdevrel.com/docs-main-doc-assets-1/2041/842a17b0-b91f-4f57-be21-196ca09290db.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

Gradle is an open-source build automation tool that streamlines multi-language development workflows, especially for large-scale Java applications. To get started, you can install Gradle on Ubuntu 24.04, which automates tasks such as compiling, testing, packaging, and deploying applications using Java, Kotlin, Scala, Android, Groovy, C++, or Swift. It also integrates with other tools and platforms to simplify the build, test, and deployment processes.

This article explains how to install Gradle on Ubuntu 24.04 and set it up to run applications on a server.

## Install Gradle on Ubuntu 24.04

You can install Gradle using the latest release file, APT or Snap on Ubuntu 24.04. Follow the steps below to use a specific installation method to install Gradle on your server.

???+ note "Install Gradle on Ubuntu 24.04 Using the Latest Release File"

    The Gradle release ZIP archive enables you to install the latest or a specific version from source. This ensures compatibility and access to up-to-date features for your applications. Follow the steps below to install the required dependency packages and download the latest Gradle release file to install on your server.

    1. Update the server's package index.

        ```console
        $ sudo apt update
        ```

    1. Install the required Java Development Kit (JDK) package.

        ```console
        $ sudo apt install default-jdk -y
        ```

    1. View the installed Java version.

        ```console
        $ java --version
        ```

    1. Visit the [Gradle release page](https://gradle.org/releases), identify the latest version, and copy its binary direct download link. Then, use `wget` to download the file. For example, download the Gradle `8.12` version.

        ```console
        $ wget https://services.gradle.org/distributions/gradle-8.12-bin.zip
        ```

    1. Extract the Gradle ZIP archive contents to a system-wide directory such as `/opt`
    
        ```console
        $ sudo unzip -d /opt/gradle gradle-8.12-bin.zip
        ```

    ### Setup Environment Variables

    Setting up a global environment variable with your Gradle installation directory allows you to execute the Gradle binary as a global system-wide command. Follow these steps to create a script in the `/etc/profile.d` directory for the new global environment variable

    1. Create a new `gradle.sh` script in the `/etc/profile.d` directory.

        ```console
        $ sudo nano /etc/profile.d/gradle.sh
        ```

    1. Add the following directives to the `gradle.sh` file.

        ```sh
        export GRADLE_HOME=/opt/gradle/gradle-8.12 
        export PATH=${GRADLE_HOME}/bin:${PATH}
        ```

        Save and close the file.

    1. Enable execute permissions on the script.

        ```console
        $ sudo chmod +x /etc/profile.d/gradle.sh
        ```

    1. Load the Gradle environment configuration in your active shell.

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

    1. Verify the installed Gradle version.

        ```console
        $ gradle --version
        ```

        Output:

        ```
        Welcome to Gradle 8.12!
        Here are the highlights of this release:
         - Enhanced Error and Warning Messages
         - IDE Integration Improvements
         - Daemon JVM Information
        For more details see https://docs.gradle.org/8.12/release-notes.html
        ------------------------------------------------------------
        Gradle 8.12
        ------------------------------------------------------------
        ```

??? note "Install Gradle on Ubuntu 24.04 Using APT"

    Gradle is available in the default APT package repositories on Ubuntu 24.04. However, the Gradle version is not the latest. Follow the steps below to install Gradle and all required dependencies using the APT package manager on your server.

    1. Update the server's package index.

        ```console
        $ sudo apt update
        ```

    1. Install Gradle.

        ```console
        $ sudo apt install gradle -y
        ```

    1. View the installed Gradle version.

        ```console
        $ gradle --version
        ```

        Your output should be similar to the one below.

        ```
        openjdk version "21.0.5" 2024-10-15
        OpenJDK Runtime Environment (build 21.0.5+11-Ubuntu-1ubuntu124.04)
        OpenJDK 64-Bit Server VM (build 21.0.5+11-Ubuntu-1ubuntu124.04, mixed mode, sharing)
        ------------------------------------------------------------
        Gradle 4.4.1
        ------------------------------------------------------------
        Build time:   2012-12-21 00:00:00 UTC
        Revision:     none
        Groovy:       2.4.21
        Ant:          Apache Ant(TM) version 1.10.14 compiled on September 25 2023
        JVM:          21.0.5 (Ubuntu 21.0.5+11-Ubuntu-1ubuntu124.04)
        OS:           Linux 6.8.0-48-generic amd64
        ```

??? note "Install Gradle on Ubuntu 24.04 Using Snap"

    Gradle is available in the Snap Store, but the included version might not be the latest. Snap offers a direct installation procedure with faster updates for installed Gradle versions.  Follow the steps below to install Gradle on your server using Snap.

    1. Install the Snap daemon if it's not installed.

        ```console
        $ sudo apt install snapd -y
        ```

    1. Search the available Gradle version in the Snap Store.

        ```console
        $ sudo snap search gradle
        ```

        Output:

        ```
        Name           Version   Publisher      Notes    Summary
        gradle         7.2       snapcrafters✪  classic  An open-source build automation tool
        gum            0.13.0    aalmiray       classic  Gum is a Gradle/Maven/Ant/Bach/JBang wrapper written in Go
        jreleaser      1.0.0-M1  aalmiray       -        Release Java projects quickly and easily with JReleaser
        om26er-gradle  4.7       om26er         -        Accelerate developer productivity
        jrel-test      1.0.0-M9  aalmiray       -        Release projects quickly and easily with JReleaser
        ```

        Gradle `7.2` is the available version in the Snap Store based on the above output.

    1. Install Gradle using Snap.

        ```console
        $ sudo snap install gradle --classic
        ```

    1. View the installed Gradle version.

        ```console
        $ sudo snap run gradle --version
        ```

        Output:

        ```
        Welcome to Gradle 7.2!
        Here are the highlights of this release:
         - Toolchain support for Scala
         - More cache hits when Java source files have platform-specific line endings
         - More resilient remote HTTP build cache behavior
        For more details see https://docs.gradle.org/7.2/release-notes.html
        ------------------------------------------------------------
        Gradle 7.2
        ------------------------------------------------------------
        ```

## Create a Basic Java Application Using Gradle

Follow the steps below to create a basic Java application and run it using Gradle on your server.

1. Create a new `sample_project` directory to use with Gradle.

    ```console
    $ mkdir sample_project
    ```

1. Switch to the `sample_project` directory.

    ```console
    $ cd sample_project
    ```

1. Initialize the Gradle project to create a basic Gradle project structure.

    ```console
    $ gradle init --type java-application
    ```

    Output:

    ```
    .........
    BUILD SUCCESSFUL in 6s
    2 actionable tasks: 2 executed
    ```

   * Press :key_enter: to use the default Java version in your project.

        ```
        Starting a Gradle Daemon (subsequent builds will be faster)

        Enter target Java version (min: 7, default: 21): 
        ```

    * Verify your project name and press :key_enter:.
    
        ```
        Project name (default: sample_project): 
        ```
    
    * Enter `1` to set up a single application project.

        ```
        Select application structure:
          1: Single application project
          2: Application and library project
        Enter selection (default: Single application project) [1..2] 
        ```

    * Select your desired build language. For example, enter `1` to select Kotlin as the build script language.

        ```
        Select build script DSL:
          1: Kotlin
          2: Groovy
        Enter selection (default: Kotlin) [1..2] 
        ```

    * Select the target test framework. For example, enter  `1` to select JUnit 4.

        ```
        Select test framework:
          1: JUnit 4
          2: TestNG
          3: Spock
          4: JUnit Jupiter
        Enter selection (default: JUnit Jupiter) [1..4] 
        ```

    * Press `yes` to use new APIs with Gradle and initialize your project.

        ```
        Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] 
        ```

    Your output should be similar to the one below when the build process is successful.

    ```
    BUILD SUCCESSFUL in 1m 5s
    1 actionable task: 1 executed
    ```

1. Create the `src/main/java` directory to store your application files.

    ```console
    $ mkdir -p src/main/java
    ```

1. Create a new `App.java` Java application file in the `src/main/java` directory using a text editor such as `nano`.

    ```console
    $ nano src/main/java/App.java
    ```

1. Add following contents to the file.

    ```java
    public class App {
        public static void main(String[] args) {
            System.out.println("Greetings from Vultr!");
        }
    }
    ```

    Save and close the file.

    The above Java program outputs a `Greetings from Vultr` message when executed.

1. Open the `build.gradle` file to ensure it includes the Java plugin and specifies the main class.

    ```console
    $ nano build.gradle
    ```

1. Add the following contents to the file.

    ```ini
    plugins {
        id 'application'
    }

    application {
        // Define the main class
        mainClass = 'App'
    }

    jar {
        manifest {
            attributes(
                'Main-Class': 'App'
            )
        }
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        // Add dependencies here if needed
    }
    ```

    Save and close the file.

1. Build and compile the Java application into a single file using Gradle.

    ```console
    $ gradle build
    ```

    The above command compiles the Java application code, runs tests, and packages the application into a single `.jar` file.

    Output:

    ```
    Calculating task graph as no cached configuration is available for tasks: build

    BUILD SUCCESSFUL in 1m 12s
    12 actionable tasks: 12 executed
    Configuration cache entry stored.
    ```

1. Run the application using Gradle.

    ```console
    $ gradle run
    ```

    Output:

    ```
    > Task :run
    Greetings from Vultr!

    > Task :app:run
    Hello World!

    BUILD SUCCESSFUL in 1s
    4 actionable tasks: 2 executed, 2 up-to-date
    ```

1. Run the bundled `.jar` file using Java.

    ```console
    $ java -jar build/libs/sample_project.jar App
    ```

    Output:

    ```
    Greetings from Vultr!
    ```

## Add Web Server Dependencies for Gradle

Gradle supports multiple dependencies to perform specific application functions. Follow the steps below to install the Spark Java web server dependency to enable Gradle to run web applications using dedicated ports on your server.

1. Open the `build.gradle` file.

    ```console
    $ nano build.gradle
    ```

1. Modify the `dependencies` section to include a new SparkJava directive.

    ```ini
    dependencies {
        // Add Spark Java for lightweight HTTP server
        implementation 'com.sparkjava:spark-core:2.9.4'
    }
    ```

    Save and close the file.

    Your modified `dependencies` section should look like the one below.

    ```ini
    dependencies {
        // Add dependencies here if needed
        // Add Spark Java for lightweight HTTP server
        implementation 'com.sparkjava:spark-core:2.9.4'
    }
    ```

1. Back up the `App.java` application file.

    ```console
    $ mv src/main/java/App.java src/main/java/App.ORIG
    ```

1. Create the `App.java` file again.

    ```console
    $  nano src/main/java/App.java
    ```

1. Add the following code to the `App.java` file to enable a basic HTTP server using Spark Java.

    ```java
    import static spark.Spark.*;

    public class App {
        public static void main(String[] args) {
            port(8080); // Set the port number

            // Define a route for the root URL
            get("/", (req, res) -> {
                res.type("text/html");
                return "<h1>Greetings from Vultr!</h1>";
            });

            System.out.println("Server is running at http://localhost:8080/");
        }
    }
    ```

    Save and close the file.

    The above modified Java application code imports the Spark Java package, runs the application on port `8080` and outputs a `Greetings from Vultr` message when accessed.

1. Allow connections to port `8080` through the default firewall.

    ```console
    $ sudo ufw allow 8080
    ```

1. Reload UFW to apply the firewall changes.

    ```console
    $ sudo ufw reload
    ```

1. Start the application using Gradle.

    ```console
    $ gradle run
    ```

    Output:

    ```
    > Task :run
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    Server is running at http://localhost:8080/
    <====---------> 37% EXECUTING [49s]
    > :run
    ```

1. Access your server's IP address on port `8080` using a web browser such as Firefox and verify that your web application displays.

    ![Application default page](https://assets.vultrdevrel.com/docs-main-doc-assets-1/2041/fa570dfd-5cfa-4bb7-a746-edd35be8879f.png)

## Uninstall Gradle on Ubuntu 24.04

Follow the steps below to uninstall Gradle on your server if necessary depending on your installation method.

1. Delete the Gradle binary to disable it on your server.

    ```console
    $ sudo rm -rf /opt/gradle/gradle-8.12/bin/gradle
    ```

1. Remove the Gradle environment variable script.

    ```console
    $ sudo rm /etc/profile.d/gradle.sh
    ```

1. Run the following command to uninstall Gradle if you installed it using APT.

    ```console
    $ sudo apt autoremove gradle -y
    ```

1. Uninstall Gradle if installed using Snap.

    ```console
    $ sudo snap remove gradle
    ```

## Conclusion

You have installed Gradle on Ubuntu 24.04 and run sample applications on your server. Gradle is highly scalable and integrates with multiple frameworks to manage and build applications. For more information and configuration options, visit the [Gradle documentation](https://docs.gradle.org/current/userguide/gradle_basics.html).
