×


Gradle is an open-source automation tool for building applications. It supports various languages including Java, Android, C/C++, and JavaScript. It is preferred by millions of developers due to its ability to automate the creation of applications which involves compiling, testing, deploying, and publishing applications.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Software Installation tasks on their Linux System.

In this context, we shall look into how to install Gradle on Ubuntu 20.04 LTS (Focal Fossa) machine.

Previously, we described the installation of Gradle on CentOS


How to Install Gradle on Ubuntu ?

For Gradle, you must have Java JDK or JRE version 8 or above installed on your Ubuntu machine. To verify if Java is running, use the command below:

$ java -version

This will indicate that Java is installed on your machine.

To install Gradle on Ubuntu, there are following three methods:

  • Installation via Direct Download.
  • Installation via Snap.
  • Installation via Apt.


1. Gradle Installation via Direct Download

Here, we will install Gradle by downloading the zip package available at Gradle official website. Using this installation method, you can get the latest version of Gradle. The complete steps for the installation of Gradle via Direct Download are as follows.

i. To download Gradle's latest version, visit the Releases page and download the binary package. As of May 2021, the latest version of Gradle available on the official Releases page is 7.0.2. So here, we are going to download the Gradle version 7.0.2. You can download it from the Releases page or use the following command to download it from the command line:

$ wget https://downloads.gradle-dn.com/distributions/gradle-7.0.2-bin.zip

ii. The downloaded file is in zip format, you will need to extract it. Use the command below to unzip it in /opt/gradle directory:

$ sudo unzip -d /opt/gradle

To verify if the file has been extracted, use the command below:

$ ls /opt/gradle/gradle-7.0.2

iii. Now, you will need to setup the environment variable. You can do this by creating a new file inside the /etc/profile.d directory:

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

Add the following lines in the file:

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

Then save and close the file.

iv. Then give the /etc/profile.d/gradle.sh file execute permission using the command below:

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

v. Now load the environment variables as follows:

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

vi. To verify the installation of Gradle and to view the version installed, use the command below:

$ gradle -v

The output will indicate the Gradle version installed on the system.


2. Gradle Installation via Snap

The snap package for Gradle is also available for installation on Ubuntu. This method also installs the latest version of Gradle on your system.

The complete steps are as follows.

i. If snapd is not installed already on your system, you can install it as follows:

$ sudo apt update
$ sudo apt install snapd

ii. Then install Gradle snap using the command below:

$ sudo snap install gradle --classic

Or you can use the following command to view detailed information:

$ /snap/bin/gradle -v


3. Gradle Installation via Apt

Another method to install Gradle is via apt. However, this method does not install the latest version of Gradle. The complete steps for the installation of Gradle via apt are as follows:

i. Update the repository index using this command:

$ sudo apt update

ii. Now to install Gradle on your system, use the command below:

$ sudo apt install gradle -y

This command will install Gradle on your system.

iii. To verify the installation of Gradle and to view the version installed, use the command below:

$ gradle -v

The output will indicate the Gradle version installed on the system.


How to Uninstall Gradle from Ubuntu System ?

If you want to remove Gradle from your system, you can do so using the following methods:

If you have installed Gradle using the direct download method, you can uninstall it as follows:

$ sudo rm gradle-7.0.2-bin.zip
$ sudo rm -r /opt/gradle /gradle.sh
$ sudo rm -r /usr/lib/gradle/

To remove Gradle installed via snap, use the command below to remove it:

$ sudo snap remove gradle

To remove Gradle installed via apt, use the command below to remove it:

$ sudo apt remove gradle


[Need assistance in fixing Software Installation task on your Linux System? We can help you. ]


Conclusion

This article covers the installation of Gradle on the Ubuntu system using different ways. Gradle is a free and open-source build tool primarily used for Java projects. Gradle helps you to automate, build and deliver software efficiently. Gradle uses Groovy object-oriented programming language instead of XML to define the project configurations. Gradle also supports many popular IDE platforms, such as Android Studio, Eclipse, IDEA, and NetBeans.


How to Install Java on Linux ?

Gradle needs Java to be installed on your system. You can install the latest version of Java by running the following command:

$ apt-get install default-jdk -y 

After installing Java, you can verify the Java with the following command:

$ java -version

More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com