How To Install Apache Ant on Ubuntu 20.04 LTS

On this short article we will discuss how to install Apache Ant version 1.10 on Ubuntu 20.04 LTS operating 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.

Apache Ant Installation On Ubuntu 20.04

There are 3 options for installing Apache Ant which will be explained in this short tutorial, namely: Via APT, SDK and manual installation. These three options will be discussed in detail below. Apache Ant Installation On Ubuntu Steps.

  • Prerequisite
  • Installing Java
  • Apache Ant Installation Options
    • Apt
    • SDK
    • Manual Download

Prerequisites

Before we are going to the install Apache Ant, we have to prepare the environment first as mentioned below :

  • Ubuntu 20.04 System with updated repository
  • a user with sudo privilege
  • Sufficient disk space and good internet access

Installing Java

Incidentally, the system I use already has Java installed. The way to verify it is by typing the command line:

$ java --version

Output :

ramans@bckinfo:~$ java --version
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

However, if there is no java installed on the system, then we must first install java by typing the command line:

$ sudo apt install openjdk-11-jre

Installing Apache Ant

1. Installing Apache Ant via APT

Apache Ant comes via Ubuntu default repositories. However, the version with comes with Ubuntu repositories might not be the latest version. If you wish to install the latest, you may have to install it manually or via third party repositories. 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 :

$ sudo apt update
$ sudo apt install ant
$ ant -version

The output :

ramans@bckinfo:~$ sudo apt update
[sudo] password for ramans: 
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease 
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [111 kB] 
Ign:3 https://pkg.jenkins.io/debian-stable binary/ InRelease
...

ramans@bckinfo:~$ sudo apt install ant
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following additional packages will be installed:
ant-optional
Suggested packages:
ant-doc antlr javacc junit junit4 jython libactivation-java libbcel-java libbsf-java libcommons-logging-java
libcommons-net-java libmail-java libjaxp1.3-java libjdepend-java libjsch-java liblog4j1.2-java liboro-java
libregexp-java libxalan2-java libxml-commons-resolver1.1-java libxz-java
The following NEW packages will be installed:
ant ant-optional
0 upgraded, 2 newly installed, 0 to remove and 231 not upgraded.
Need to get 2,468 kB of archives.
After this operation, 3,415 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...
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) ...
ramans@bckinfo:~$ ant -version
Apache Ant(TM) version 1.10.7 compiled on October 24 2019

2. Apache Ant installation Via SDKMAN

Installing Apache Ant using SDK requires SDKMAN. If our system did not have SDKMAN yet, just install it first. SDKMAN is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. You’ll need to install SDKMan too. Installing SDKMAN! on UNIX-like platforms is as easy as ever. Run the following commands below to download and install SDK and Ant.

$ curl -s "https://get.sdkman.io" | sudo bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
# sdk install ant
# ant -version

The output will be shown below :

ramans@bckinfo:~$ curl -s "https://get.sdkman.io" | sudo bash

-+syyyyyyys:
`/yho:` -yd.
`/yh/` +m.
.oho. hy .`
.sh/` :N` `-/o` `+dyyo:.
.yh:` `M- `-/osysoym :hs` `-+sys: hhyssssssssy+
.sh:` `N: ms/-`` yy.yh- -hy. `.N-````````+N.
`od/` `N- -/oM- ddd+` `sd: hNNm -N:
:do` .M. dMMM- `ms. /d+` `NMMs `do
.yy- :N` ```mMMM. - -hy. /MMM: yh
`+d+` `:/oo/` `-/osyh/ossssssdNMM` .sh: yMMN` /m.
-dh- :ymNMMMMy `-/shmNm-`:N/-.`` `.sN /N- `NMMy .m/
`oNs` -hysosmMMMMydmNmds+-.:ohm : sd` :MMM/ yy
.hN+ /d: -MMMmhs/-.` .MMMh .ss+- `yy` sMMN` :N.
:mN/ `N/ `o/-` :MMMo +MMMN- .` `ds mMMh do
/NN/ `N+....--:/+oooosooo+:sMMM: hMMMM: `my .m+ -MMM+ :N.
/NMo -+ooooo+/:-....`...:+hNMN. `NMMMd` .MM/ -m: oMMN. hs
-NMd` :mm -MMMm- .s/ -MMm. /m- mMMd -N.
`mMM/ .- /MMh. -dMo -MMMy od. .MMMs..---yh
+MMM. sNo`.sNMM+ :MMMM/ sh`+MMMNmNm+++-
mMMM- /--ohmMMM+ :MMMMm. `hyymmmdddo
MMMMh. ```` `-+yy/`yMMM/ :MMMMMy -sm:.``..-:-.`
dMMMMmo-.``````..-:/osyhddddho. `+shdh+. hMMM: :MmMMMM/ ./yy/` `:sys+/+sh/
.dMMMMMMmdddddmmNMMMNNNNNMMMMMs sNdo- dMMM- `-/yd/MMMMm-:sy+. :hs- /N`
`/ymNNNNNNNmmdys+/::----/dMMm: +m- mMMM+ohmo/.` sMMMMdo- .om: `sh
`.-----+/.` `.-+hh/` `od. NMMNmds/ `mmy:` +mMy `:yy.
/moyso+//+ossso:. .yy` `dy+:` .. :MMMN+---/oys:
/+m: `.-:::-` /d+ +MMMMMMMNh:`
+MN/ -yh. `+hddhy+.
/MM+ .sh:
:NMo -sh/
-NMs `/yy:
.NMy `:sh+.
`mMm` ./yds-
`dMMMmyo:-.````.-:oymNy:`
+NMMMMMMMMMMMMMMMMms:`
-+shmNMMMNmdy+:`


Now attempting installation...


Looking for a previous installation of SDKMAN...
Looking for unzip...
Looking for zip...
Looking for curl...
Looking for sed...
Installing SDKMAN scripts...
Create distribution directories...
Getting available candidates...
Prime the config file...
Download script archive...
######################################################################## 100.0%
Extract script archive...
Install scripts...
Set version to 5.9.0+555 ...
Attempt update of interactive bash profile on regular UNIX...
Added sdkman init snippet to /root/.bashrc
Attempt update of zsh profile...
Updated existing /root/.zshrc

ramans@bckinfo:~$ source "$HOME/.sdkman/bin/sdkman-init.sh"
ramans@bckinfo:~$ sdk version

SDKMAN 5.9.0+555

After SDKMAN installation was completed done, then we will install Apache Ant based on it.

ramans@bckinfo:~$ sudo bash
root@bckinfo:/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.
root@bckinfo:/home/ramans#

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

3. Installing Apache Ant Via Source File

By using this option, we will install Apache Ant use Apache Ant source file, download, extract, make Ant source file. By using wget command line, we will download and by using tar command line we will extract the file and make it to be in executed file.

$ wget http://mirror.downloadvn.com/apache//ant/binaries/apache-ant-1.10.8-bin.tar.gz
$ sudo tar -xf apache-ant-1.10.8-bin.tar.gz -C /usr/local
$ sudo ln -s /usr/local/apache-ant-1.10.8/ /usr/local/ant
$ sudo vi /etc/profile.d/ant.sh
$ source /etc/profile
$ ant -version

The output will be shwond below ;

ramans@bckinfo:~$ cd /tmp
ramans@bckinfo:/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]

ramans@bckinfo:/tmp$ sudo tar -xf apache-ant-1.10.8-bin.tar.gz -C /usr/local

ramans@bckinfo:/tmp$ sudo tar -xf apache-ant-1.10.8-bin.tar.gz -C /usr/local
ramans@bckinfo:/tmp$ sudo ln -s /usr/local/apache-ant-1.10.8/ /usr/local/ant
ramans@bckinfo:/tmp 
export ANT_HOME=/usr/local/ant
export PATH=${ANT_HOME}/bin:${PATH}

ramans@bckinfo:/tmp$ source /etc/profile
ramans@bckinfo:/tmp$ ant -version
Apache Ant(TM) version 1.10.8 compiled on May 10 2020

Conclusion

On this short article, we have discussed how to install Apache Ant on Ubuntu 20.04 LTS operating system. There are three options to install Apache Ant, namely : via APT, SDKMAN and manual installation. I hope this short article will be helpful.

Add a Comment

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