How to install Apache Ant on Ubuntu 20.04 LTS

How To Install Apache Ant On Ubuntu 20.04 LTS

On this article we will discuss how to install Apache Ant on Ubuntu 20.04 LTS system.

Introduction

When we are going to develop Java applications, sometimes we need a tool to automate the process, we need a Java library which is capable to compile, assemble, test and run Java applications. Apache Ant is a software tool for automating software build processes especially on Java environments. Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications.

Apache Ant Version

Apache Ant is written in Java. The last stable release of Apache Ant are : 1.9.15 and 1.10.8 which were released on May 13, 2020 and now available for download as source or binary from https://ant.apache.org/bindownload.cgi.

The Apache Ant team currently maintains two lines of development. The 1.9.x releases require Java5 at runtime and 1.10.x requires Java8 at runtime. Both lines are based off of Ant 1.9.7 and the 1.9.x releases are mostly bug fix releases while additional new features are developed for 1.10.x. We recommend using 1.10.x unless you are required to use versions of Java prior to Java 8 during the build process.

Apache Ant Installation On Ubuntu 20.04 LTS

On this tutorial, we will install Apache Ant version 1.10.8 which require Java 8 runtime. The installation process will consist of several stages, namely:

  • Prerequisite
  • Install Apache Ant
    • Using Ubuntu Apt
    • Using SDKMAN
    • Download and Install Manually

Prerequisite

We have to prepare Ubuntu 20.04 LTS system with good internet connection and sufficient disk space for Apache Ant binary file. Java 8 Development Kit (official Oracle JDK or Open JDK) installed on our system. As mentioned on Apache Ant documentation, this software requires Java 8. So we have to prepare it first.

Verifying Java version

On our system, there are more than one Java version installed, we can switch it to a proposed version.

ramans@otodiginet:~$ sudo update-alternatives --config java
[sudo] password for ramans:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode

Press to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode

We choose Java version 8 for this installation purpose and verifty its version.

ramans@otodiginet:~$ java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
Java JDK version

1. Install Apache Ant (Using Ubuntu Apt)

The Ubuntu default repositories contain Apache Ant, but might not be the latest version. To install Apache Ant using apt-get is a simple thing, just submit command line below :

ramans@otodiginet:~$ sudo apt update
ramans@otodiginet:~$ sudo apt install ant

The output will be as follow :

Selecting previously unselected package ant.
(Reading database … 224892 files and directories currently installed.)
Preparing to unpack …/archives/ant_1.10.7-1_all.deb …
Unpacking ant (1.10.7-1) …
Selecting previously unselected package ant-optional.
Preparing to unpack …/ant-optional_1.10.7-1_all.deb …
Unpacking ant-optional (1.10.7-1) …
Setting up ant (1.10.7-1) …
Setting up ant-optional (1.10.7-1) …
Processing triggers for man-db (2.9.1-1) …

Verifying Apache Ant with querying its version :

ramans@otodiginet:~$ ant -version
Apache Ant(TM) version 1.10.7 compiled on October 24 2019
Apache Ant Installation
Apache Ant(TM) version 1.10.7

2. Install Apache Ant using SDK

On our system is already SDK installed, we can verify it by using command line below :

ramans@otodiginet:~$ sdk version
SDKMAN 5.9.0+555

Install Apache usind SDK.

ramans@otodiginet:~$ sudo bash
root@otodiginet:/home/ramans# sdk install ant
==== BROADCAST =================================================================
2020-09-21: jbang 0.47.1 now available for download.
2020-09-20: jbang 0.46.1 @jbangdev https://git.io/JUEb5
* 2020-09-20: jbang 0.46.0 @jbangdev https://git.io/JUEHD
Downloading: ant 1.10.8
In progress…
################################################################################################################ 100.0%
Installing: ant 1.10.8
Done installing!
Setting ant 1.10.8 as default.
{nstall Apache Ant using SDK

Verify Apache Ant, by submittinc command line below :

root@otodiginet:/home/ramans# ant -version
Apache Ant(TM) version 1.10.8 compiled on May 10 2020
Apache Ant(TM) version 1.10.8

3. Install Apache Ant Manually

The third option for installing Apache Ant is by download and extract the source manually.

ramans@otodiginet:~$ cd /tmp
ramans@otodiginet:/tmp$ wget http://mirror.downloadvn.com/apache//ant/binaries/apache-ant-1.10.8-bin.tar.gz
--2020-09-20 18:15:00-- http://mirror.downloadvn.com/apache//ant/binaries/apache-ant-1.10.8-bin.tar.gz
Resolving mirror.downloadvn.com (mirror.downloadvn.com)… 104.24.98.3, 172.67.136.9, 104.24.99.3, …
Connecting to mirror.downloadvn.com (mirror.downloadvn.com)|104.24.98.3|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 6884228 (6.6M) [application/octet-stream]
Saving to: ‘apache-ant-1.10.8-bin.tar.gz’
apache-ant-1.10.8-bin.tar.gz 100%[====================================================>] 6.56M 9.14KB/s in 9.8s
2020-09-20 18:15:14 (688 KB/s) - ‘apache-ant-1.10.8-bin.tar.gz’ saved [6884228/6884228]
Download Apache Ant source files

The binary source file is located on /tmp directory, then we extract them to /usr/local directory and make the profile.

ramans@otodiginet:/tmp$ sudo tar -xf apache-ant-1.10.8-bin.tar.gz -C /usr/local
ramans@otodiginet:/tmp$ sudo ln -s /usr/local/apache-ant-1.10.8/ /usr/local/ant
ramans@otodiginet:/tmp$ sudo vi /etc/profile.d/ant.sh
export ANT_HOME=/usr/local/ant
export PATH=${ANT_HOME}/bin:${PATH}
ramans@otodiginet:/tmp$ source /etc/profile

Than verify its version by submitting command line below :

ramans@otodiginet:/tmp$ ant -version
Apache Ant(TM) version 1.10.8 compiled on May 10 2020
Extract Apache Ant binary file to /usr/local directory

Conclusion

So far, Apache Ant installation has been completed done. Ther are three option Apache Ant installation, namely : via Ubuntu Apt, SDK and install manually. I hope this article will be useful for whom who is searching Apache Ant installation.

Have a nice day. Stay at home and stay safe.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *