Choose a different version or distribution
Introduction
Gradle is a build automation tool used to create a variety of applications, including microservices and mobile applications. 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 parallel execution of tasks and intra-tasks through a worker API, Gradle enhances the performance of applications. Each time can be limited to the execution time, as these tasks have their own timeout property.
Install Gradle on Ubuntu 22.04 from its official website
To install Gradle, we will download its package from the official website and then carry out the procedures below.
Step 1 - Install Java on Ubuntu
Gradle depends on Java, thus we will first use the following command to install the most recent Java version that is available in Ubuntu's default repository:
sudo apt install default-jdk -y
We'll examine the Java package version that has been installed:
java --version
Step 2: Download Gradle Package
Using the wget command, we will now download the Gradle package from its official website and store it in the Ubuntu tmp directory after installing Java:
wget -c https://services.gradle.org/distributions/gradle-7.4.2-bin.zip -P /tmp
To verify that the package was downloaded, we'll list it down:
ls /tmp
Step 3: Unzip the Downloaded Package of Gradle
The downloaded package is zipped; to unzip it, use the following command:
sudo unzip -d /opt/gradle /tmp/gradle-7.4.2-bin.zip
Use the ls command to once more list the unzipped files:
ls /opt/gradle
Step 4: Set up Environment Variables
The next step is to configure the environment variables; for this, we will make some changes to Gradle's "sh" file. To do so, we have to open it with the nano text editor:
sudo nano /etc/profile.d/gradle.sh
Add the two lines shown below to the file you just opened, then save your modifications before closing the editor:
export GRADLE_HOME=/opt/gradle/gradle-7.4.2
export PATH=${GRADLE_HOME}/bin:${PATH}
Step 5: Change the Permissions of File
We will use the chmod command to modify the "sh" file's permissions so that it can be executed:
sudo chmod +x /etc/profile.d/gradle.sh
Step 6: Install the Gradle
The environment variables should then be loaded using:
source /etc/profile.d/gradle.sh
We will check the installed Gradle version to verify the installation:
gradle --version
How to Install Gradle on Ubuntu 22.04 using the snap
Another way to install Gradle on Ubuntu is by downloading it from the snapcraft. To do this, you'll need the snapd
utility, which you can get by using the following command:
sudo apt install snapd -y
Use the following command to download and install Gradle as a snap from Snapcraft:
sudo snap install gradle --classic
Use the following command to remove the Gradle installation package:
sudo snap remove gradle
FAQs to Install Gradle on Ubuntu 22.04
How do I check if Gradle is installed on Ubuntu 22.04?
You can check if Gradle is installed on Ubuntu 22.04 by running the command gradle -v
in the terminal. If Gradle is installed, it will display the version number.
How do I uninstall Gradle from Ubuntu 22.04?
To uninstall Gradle from Ubuntu 22.04, you can use the package manager by running the command sudo apt remove gradle
. You may also need to remove any Gradle-related files or directories manually.
Can I install a specific version of Gradle on Ubuntu 22.04?
Yes, you can install a specific version of Gradle on Ubuntu 22.04 by downloading the binary from the Gradle website and installing it manually.
What are the system requirements for installing Gradle on Ubuntu 22.04?
To install Gradle on Ubuntu 22.04, you need a minimum of 4GB of RAM and 2 CPU cores. You also need Java Development Kit (JDK) version 8 or later installed.
How do I set up environment variables for Gradle on Ubuntu 22.04?
To set up environment variables for Gradle on Ubuntu 22.04, you need to add the Gradle installation directory to the PATH environment variable. You can do this by editing the .bashrc file in your home directory.
Conclusion
Gradle is a tool for developing, automating, testing, and maintaining applications, whether they are mobile or meant to offer microservices. In this tutorial, the installation process for Gradle on Ubuntu has been explored by downloading the package from its official website.
If you have any suggestions or queries, kindly leave them in the comments section.