Site icon Linux Genie

How to Install Gradle on Ubuntu 24.04

Gradle ubuntu

Gradle is an open-source general-purpose versatile tool for building and automating almost any software. It is a useful tool for projects written in Java, C, C++, and Swift. Unlike XML, Gradle uses the Groovy and Kotlin programming languages to define projects and develop more flexible and expressive scripts. The Gradle first compiles and tests the code then packages the project and makes it ready for development.

If you have installed the Ubuntu 24.04 system on a computer or Virtual Machine, read this guide to learn:

How to Install Gradle on Ubuntu 24.04

You can install Gradle on Ubuntu 24.04 from:

How to Install Gradle on Ubuntu 24.04 from the Official Zip File

The official way to install Gradle on Ubuntu 24.04 is to download the zip file and perform the necessary configuration to complete the installation. The advantage of using the official method for Gradle installation is that you will manage to install Gradle’s latest version on your system.

Follow the provided steps to install Gradle on Ubuntu 24.04 from the zip file:

Step 1: Install Java on Ubuntu

Before installing Gradle on Ubuntu, you must ensure installing Java on your system. You can install Java on Ubuntu 24.04 using the apt package manager, SDKMAN, or deb package. The straightforward way to install Java on Ubuntu is through the apt package manager via the provided command:

sudo apt install default-jdk -y

You can confirm the Java installation on Ubuntu from the below-given command:

java --version

Step 2: Download the Gradle Zip File

Now, open the Firefox browser on Ubuntu, navigate to the Gradle official release page, and download the latest version binary-only (zip) file. The latest version of Gradle, while writing this article, was 8.6 released on Feb 02, 2024. You can select your desired Gradle version and download it on your system directly from the browser.

 

Alternatively, you can execute the wget command to directly download the Gradle latest version (8.6) into the /tmp directory:

wget https://services.gradle.org/distributions/gradle-8.6-bin.zip -P /tmp

Step 3: Unzip the Gradle Zip File

Next, unzip the Gradle zip file to the /opt/gradle location from the /tmp directory to have more control over version and updates, it can be done using the following command:

sudo unzip -d /opt/gradle /tmp/gradle-8.6-bin.zip

Step 4: Setup Environment Variable

You must need to set up an environment variable for Gradle on Ubuntu so that the system will know the exact location of the Gradle source directory, You can do this by creating a script file inside the /etc/profile.d location using a text editor (nano) via below-given command:

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

Then add the following two lines inside the gradle.sh file:

export GRADLE_HOME=/opt/gradle/gradle-8.6

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

Note: Make sure to replace the version number of Gradle with the version you have installed on Ubuntu.

Step 4: Make the Gradle Script File Executable

You should now use the following chmod command on Ubuntu to make the Gradle script file executable:

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

 

Step 5: Load the Changes

After you provide the necessary executable rights to gradle.sh script file, you must reload the changes on Ubuntu using the following command:

source /etc/profile.d/gradle.sh

Step 6: Confirm the Gradle Installation

Once everything is done, you can confirm the Gradle installation on Ubuntu using the following command:

gradle --version

Note: If you want to remove Gradle from Ubuntu, simply remove the source directory using the following command:

sudo rm -rf /opt/gradle/gradle-8.6/bin/gradle

Then remove the script file from Ubuntu to complete the uninstallation of Gradle:

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

How to Install Gradle on Ubuntu 24.04 from Apt Package Manager

Ubuntu standard repository also includes the older version of Gradle that can be installed on the system from the following apt command:

sudo apt install gradle -y

 

Once done, you can confirm the Gradle installation on Ubuntu using the following command:

gradle --version

Note: To remove Gradle from Ubuntu 24.04 installed through apt, you can use the following command:

sudo apt remove gradle -y

How to Install Gradle on Ubuntu 24.04 from Snap Store

You can also use the Snap package manager pre-installed on the Ubuntu system for Gradle installation. To perform the Gradle installation on Ubuntu through Snap Store, run the given command:

sudo snap install gradle --classic

Note: In case Snap Store is not installed or accidentally removed, you can re-install it from the following command:

sudo apt install snapd -y

To confirm Gradle is installed on Ubuntu through Snap Store, you can run the below-given command to check the version:

sudo snap run gradle --version

Note: To remove Gradle from Ubuntu 24.04 installed through Snap Store, use the below-given command:

sudo snap remove gradle

Conclusion

Gradle is a powerful tool that simplifies the process of building software and installing it on Ubuntu to ensure a smooth development experience. You can install Gradle on Ubuntu 24.04 from the official zip file, apt package manager, or Snap Store. Using the official zip file method is recommended since it helps you install the Gradle latest version with all its latest tools. However, choosing the apt package manager or Snap Store for installing Gradle on Ubuntu won’t be a bad option too, especially for beginners. All these methods are discussed in the above section of this guide. Choose your preferred methods and start building your applications on the Ubuntu system.

Exit mobile version