Gradle is a build automation tool used to create various applications, including microservices and mobile apps. Gradle offers a platform for creating, testing, and maintaining applications. In addition, if you are working on a multi-build project, Gradle monitors the project continually and produces the output in accordance with any changes you make, no matter how small. By enabling the concurrent execution of tasks and intra-tasks through a worker API, Gradle enhances the performance of applications.
Gradle may be installed on any Linux distribution using this guide, however, in this post, we are focusing on Ubuntu.
Install Gradle
Gradle depends on Java, thus we will first use the following tutorial to install the most recent Java version that is available in Ubuntu’s default repository: How to install Java on Ubuntu
Once java is installed and ready to be used in your Ubuntu machine, we can move on to the next part. Run the following command to test if java is correctly installed.
java --version

If the output for the above command is similar to the image displayed, you have Java installed properly and we can continue.
Install Gradle using the snap command
Ubuntu ships with the snap command, we will use this command to install Gradle, it is the fastest and safest way to install Gradle.
Run the following command
sudo snap install gradle --classic
Gradle should now be installed in your Ubuntu system. Use the following command to confirm gradle installation.
gradle -v
You should see an out like the following

Install Gradle From Source
To install any version of Gradle from its source, download its release package from the official Gradle website using wget with the following command.
wget -c https://services.gradle.org/distributions/gradle-7.4.2-bin.zip -P /tmp
This downloads the gradle package in /tmp directory of your Ubuntu machine.
Unzip it into /opt/gradle directory with the following command
sudo unzip -d /opt/gradle /tmp/gradle-7.4.2-bin.zip
Create a file /etc/profile.d/gradle.sh to add Gradle in your terminal’s path
sudo nano /etc/profile.d/gradle.sh
Add the following content to it
export GRADLE_HOME=/opt/gradle/gradle-7.4.2
export PATH=${GRADLE_HOME}/bin:${PATH}
Make sure you have got the correct version after /opt/gradle/gradle-x.x.x
Make the file executable
sudo chmod +x /etc/profile.d/gradle.sh
Finally, load this file into your current session
source /etc/profile.d/gradle.sh
Gradle is successfully installed in your Linux system!
Conclusion
We learned how to install Gradle on Ubuntu with snap and how to install Gradle on any Linux distribution by downloading its package from the official website.