How to Install Gradle on Ubuntu 20.04
This tutorial exists for these OS versions
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
- Ubuntu 18.04 (Bionic Beaver)
On this page
Gradle is a tool that is used to automate software, and its users utilize this tool to build different kinds of software as well. The tool is used for Java, C++, and many other Swift projects to handle them much better. Gradle has many best features that are mandatory for development helping in the productivity of developers. It supports many languages and users can automate the development per the requirements. In this article, we will acquire the method of installation of Gradle on Ubuntu 20.04. We will download the latest version from their official website and see ways of downloading the application in the system.
Installation of Gradle
To install Gradle on Ubuntu, open up the terminal window using the Ctl+Alt+T shortcut. You can access it via Applications->Terminal as well.
Once you have opened the terminal, you need to update the apt package using:
$ sudo apt update
In Linux platforms, to make such updates and installations users need to have a sudo right privilege. Once you press <enter> system might ask for your password, in that case provide one then hit <enter>. The package will begin to update.
Installing Open JDK
Gradle needs Java SE 8 or above version installed on your machine. So, we will install it before proceeding. Once you have updated the apt package you need to type:
$ sudo apt install openjdk-11-jdk
As soon as you hit enter, the installation will begin as shown in the figure below, here you would notice that the system will ask for your permission. Type Y which implies yes to proceed with the installation process.
The process of installation will continue and Open JDK will begin to install. Here we are installing openjdk-11, you can use any latest version above 8 to proceed.
This is a time taking process so do not exit the terminal otherwise the installation process will stop and you will not be able to proceed to the next step.
After a while, when the installation of JDK is complete, you can verify it by using
$ java -version
An output like this will show the successful installation of the Java version that is much needed to proceed further.
Downloading Gradle
We will download the upgraded version of Gradle. For that, you have to go the Gradle website and check out the versions available for it on their release page. At the time of download, the latest version available on this page was 6.7.1, you can check out more options if they are available. The method of installation will remain same for all. To download the version, select Binary-only option available again Download field.
As soon as we click on the Download option, the system will ask for the choice. Select Save File option to save the file, then press the OK button. The download will begin, you can preview the shortcut from the right corner of the browser where all downloads are listed. The download might take some time so make sure to stay there and do not exit the browser before the download is complete. The downloaded file can be viewed in the Downloads directory. Go to the downloads using:
$ Downloads
To download Gradle binary zip file in /tmp directory use:
$ wget https://services.gradle.org/distributions/gradle-${VERSION}-bin.zip -P /tmp
In our case, version is 6.7.1, replace the version you downloaded on your system with the {Version} field.
Once the download process is complete, unzip the file using:
$ sudo unzip -d /opt/gradle /tmp/gradle-${VERSION}-bin.zip
It will be saved in /opt/gradle directory. If you face any issue while following this step then simply type
$ sudo apt install unzip
The package will be installed and you can continue the installation process.
Gradle is the package that get multiple updates regularly. The security patches and all kinds of new features have a lot more control over the available versions and updates. To get the updates type using:
$ sudo ln -s /opt/gradle/gradle-${VERSION} /opt/gradle/latest
In our case the version was 6.7.1, you can mention the version used by you at the time of download.
Setting up the Environment Variables
Now the final step is to set up variables for the environment. For this we are adding the Gradle bin directory to the system's PATH environment variable. Open and create a new file in the text editor. You will name this file gradle.sh and place it inside the /etc/profile.d/ directory. You can use the appended command:
$ sudo nano /etc/profile.d/gradle.sh
The GNU Nano window will open up in your Ubuntu system as shown in the figure below. Type the following in the /etc/profile.d/gradle.sh window.
export GRADLE_HOME=/opt/gradle/latest
export PATH=${GRADLE_HOME}/bin:${PATH}
Once done, save and close this file. The script you entered will then be sourced at the shell startup.
Now, to make the script executable use:
$ sudo chmod +x /etc/profile.d/gradle.sh
In order to load the environment variables in the current shell session use the cited below command:
$ source /etc/profile.d/gradle.sh
Once, done you can verify the installation process using
$ gradle -v
This way you can install the latest version of Gradle on Ubuntu 20.04 system and enjoy the development features available in the Gradle software.
Conclusion:
In this tutorial, we went through the method of installation of Gradle on Ubuntu 20.04 system. The process requires the installation of Open JDK/ Java version to proceed further. Once users have installed Java, they can download Gradle and install it on their computer systems. Setting up the environment variables is also quite an important step in the installation of Gradle. We discussed all mandatory to-do things in this article in detail. After following the step-by-step process, users can use Gradle on the go whenever they need it.