This post will guide you how to install Gradle on your Ubuntu Linux 18.04 or 16.04. How do I install Gradle from PPA on Ubuntu Linux system.
- What is Gradle?
- Prerequisites
- Step1: Installing OpenJDK
- Step2: Downloading and Installing Gradle Package
- Step3: Configuring Environment Variables for Gradle
- Installing Gradle from PPA Repository
What is Gradle?
Gradle is build automation evolved. Gradle can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites, generated documentation or indeed anything else. Gradle combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build.
Gradle is an opensource build tool used mainly for Java projects. And this tool uses Groovy which is an object-oriented programming language to define Java projects and build scripts. Gradle also can be used to build Android projects in Android Studio.
Gradle can work with many of popular JAVA IDE Tools, such as: Eclipse IDEA, NetBeans and Android Studio.
This post will show you two methods to install Gradle on Ubuntu or Debian Linux system.
Prerequisites
- Before you get started with this post, and you need to have a non-root user with sudo privileges so that you can update or install packages under Ubuntu system.
- Before you begin, you also need to update the package index and all installed packages to the latest version on your Ubuntu system with the following steps:
$ sudo apt update $ sudo apt upgrade
Step1: Installing OpenJDK
Gradle requires JAVA JDK environment or JRE version 7 or above to be installed on your Ubuntu system. You can install either the Oracle JAVA Standard Edition 8 or OpenJDK 8 on the system.
The OpenJDK 8 is already available in the default Ubuntu APT repository. So we try to install the OpenJDK 8 on this guide, just type the following command to update the packages index and installing OpenJDK 8:
$ sudo apt install openjdk-8-jdk
Outputs:
devops@devops:~$ sudo apt install openjdk-8-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
ca-certificates-java libxt-dev openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
Suggested packages:
libxt-doc openjdk-8-demo openjdk-8-source visualvm icedtea-8-plugin fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei fonts-wqy-zenhei
The following NEW packages will be installed:
ca-certificates-java libxt-dev openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
0 upgraded, 6 newly installed, 0 to remove and 45 not upgraded.
Need to get 37.5 MB/37.5 MB of archives.
After this operation, 143 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
After JDK package is installed, you can check the installation of JDK package by print the version of JDK installed, type:
$ java -version
Outputs:
devops@devops:~$ java -version openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
Note: If you want to install the Oracle JAVA 8 on your Ubuntu system, just issue the following commands:
$ sudo add-apt-repository ppa:webupd8team/java $ sudo apt update $ sudo apt install oracle-java8-installer –y
Step2: Downloading and Installing Gradle Package
Once OpenJDK 8 is installed on your Ubuntu system, you can download the latest version of Gradle from official Gradle web site. And at the time of writing this post, the latest release version of Gradle is 5.5.1.
Before you install the Gradle with the below command, you should go to the official Gradle site to check if there is new version available. Just running the following to download Gradle with wget command:
$ wget https://services.gradle.org/distributions/gradle-5.5.1-bin.zip
Outputs:
devops@devops:~$ wget https://services.gradle.org/distributions/gradle-5.5.1-bin.zip
--2019-08-03 06:04:32-- https://services.gradle.org/distributions/gradle-5.5.1-bin.zip
Resolving services.gradle.org (services.gradle.org)... 104.18.191.9, 104.18.190.9, 2606:4700::6812:bf09, ...
Connecting to services.gradle.org (services.gradle.org)|104.18.191.9|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://downloads.gradle-dn.com/distributions/gradle-5.5.1-bin.zip [following]
--2019-08-03 06:04:33-- https://downloads.gradle-dn.com/distributions/gradle-5.5.1-bin.zip
Resolving downloads.gradle-dn.com (downloads.gradle-dn.com)... 125.39.174.192, 240e:c1:5ff0:1:0:2:e8f:214c
Connecting to downloads.gradle-dn.com (downloads.gradle-dn.com)|125.39.174.192|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 89152247 (85M) [application/zip]
Saving to: ‘gradle-5.5.1-bin.zip’
gradle-5.5.1-bin.zip 100%[===================================================================================>] 85.02M 4.89MB/s in 17s
2019-08-03 06:04:53 (4.96 MB/s) - ‘gradle-5.5.1-bin.zip’ saved [89152247/89152247]
Once Gradle archive file is downloaded in your local disk, and you should extract it to /opt/gradle directory. Just run the command below to extract the gradle zip file into the /opt/gradle directory:
$ sudo unzip -d /opt/gradle gradle-5.5.1-bin.zip
Outputs:
devops@devops:~$ sudo unzip -d /opt/gradle gradle-5.5.1-bin.zip [sudo] password for devops: Archive: gradle-5.5.1-bin.zip creating: /opt/gradle/gradle-5.5.1/ inflating: /opt/gradle/gradle-5.5.1/getting-started.html inflating: /opt/gradle/gradle-5.5.1/LICENSE inflating: /opt/gradle/gradle-5.5.1/NOTICE creating: /opt/gradle/gradle-5.5.1/init.d/ inflating: /opt/gradle/gradle-5.5.1/init.d/readme.txt creating: /opt/gradle/gradle-5.5.1/media/ inflating: /opt/gradle/gradle-5.5.1/media/gradle-icon-128x128.png inflating: /opt/gradle/gradle-5.5.1/media/gradle-icon-16x16.png inflating: /opt/gradle/gradle-5.5.1/media/gradle-icon-24x24.png inflating: /opt/gradle/gradle-5.5.1/media/gradle-icon-256x256.png inflating: /opt/gradle/gradle-5.5.1/media/gradle-icon-32x32.png ……
Step3: Configuring Environment Variables for Gradle
Now you have extracted Gradle files into /opt/gradle directory, and you still need to configure ubuntu environment variables for Gradle. So you can configure the PATH environment variable to include the Gradle bin directory. To do this, you can create a new shell script called mygradle.sh in the /etc/profile.d/ directory with vim text editor, and add the following lines into this script file, type:
$ sudo vim /etc/profile.d/mygradle.sh
Adding the following lines:
export GRADLE_HOME=/opt/gradle/gradle-5.5.1/ export PATH=${GRADLE_HOME}/bin:${PATH}
Save and close the file. And you still need to change this file permission as executable using following command:
$ sudo chmod u+x /etc/profile.d/mygradle.sh
Then you can load the environment variables using the source command, type:
$ source /etc/profile.d/mygradle.sh
Now the installation of Gradle is completed, and you can verify the installation of Grade if it can work well with the gradle -v command to display the installed version of the Gradle on your Ubuntu system. Type:
$ gradle -v
Outputs:
devops@devops:~$ gradle -v Welcome to Gradle 5.5.1! Here are the highlights of this release: - Kickstart Gradle plugin development with gradle init - Distribute organization-wide Gradle properties in custom Gradle distributions - Transform dependency artifacts on resolution For more details see https://docs.gradle.org/5.5.1/release-notes.html ------------------------------------------------------------ Gradle 5.5.1 ------------------------------------------------------------ Build time: 2019-07-10 20:38:12 UTC Revision: 3245f748c7061472da4dc184991919810f7935a5 Kotlin: 1.3.31 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.14 compiled on March 12 2019 JVM: 11.0.4 (Ubuntu 11.0.4+11-post-Ubuntu-1ubuntu218.04.3) OS: Linux 4.18.0-25-generic amd64
If you get the above information for Gradle, it indicates that the Gradle has been installed on your Ubuntu system successfully.
Installing Gradle from PPA Repository
You can also use a PPA repository to install Gradle on your Ubuntu or Debian system, just do the following steps:
#1. Adding PPA repository to your system APT repositories by running the following command:
$ sudo add-apt-repository ppa:cwchien/gradle
Outputs:
devops@devops:~$ sudo add-apt-repository ppa:cwchien/gradle Gradle is a Groovy based build system. Gradle is build automation evolved. Gradle can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites, generated documentation or indeed anything else. Gradle combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build. Powered by a Groovy DSL and packed with innovation, Gradle provides a declarative way to describe all kinds of builds through sensible defaults. Gradle is quickly becoming the build system of choice for many open source projects, leading edge enterprises and legacy automation challenges. More info: <http://gradle.org/> More info: https://launchpad.net/~cwchien/+archive/ubuntu/gradle Press [ENTER] to continue or Ctrl-c to cancel adding it. Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease Hit:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease Hit:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease Hit:4 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease Hit:5 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease Get:6 http://ppa.launchpad.net/cwchien/gradle/ubuntu bionic InRelease [15.4 kB] Ign:7 https://apache.bintray.com/couchdb-deb bionic InRelease Get:9 https://apache.bintray.com/couchdb-deb bionic Release [1,840 B] Hit:10 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic InRelease Hit:8 https://packagecloud.io/slacktechnologies/slack/debian jessie InRelease Hit:12 http://ppa.launchpad.net/flexiondotorg/minecraft/ubuntu bionic InRelease Get:13 http://ppa.launchpad.net/cwchien/gradle/ubuntu bionic/main i386 Packages [1,676 B] Get:14 http://ppa.launchpad.net/cwchien/gradle/ubuntu bionic/main amd64 Packages [1,676 B] Get:15 http://ppa.launchpad.net/cwchien/gradle/ubuntu bionic/main Translation-en [1,036 B] Fetched 21.6 kB in 6s (3,771 B/s) Reading package lists... Done
From the above outputs, you should see that Gradle repository has been added into your system repository.
#2 once Gradle repository is added into your system, you need to update the system using the following command:
$ sudo apt update
#3 now you can begin to install Gradle with the following apt command.
$ sudo apt install gradle
Outputs:
devops@devops:~$ sudo apt install gradle
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
gradle-5.5.1 gradle-ppa
The following NEW packages will be installed:
gradle gradle-5.5.1 gradle-ppa
0 upgraded, 3 newly installed, 0 to remove and 112 not upgraded.
Need to get 89.1 MB of archives.
After this operation, 102 MB of additional disk space will be used.
Do you want to continue? [Y/n]Y
Conclusion
You should know that how to install Gradle tool on your Ubuntu or Debian Linux. If you want to see more detailed information about postman, you can directly go to its official web site.