How to install Apache Ant on Ubuntu

How to install Apache Ant on Ubuntu

Apache Ant is a Java based build tool that was developed by Apache Software Foundation, which is used to build files that are written in XML. Apache Ant is a java library and command line tool so it is required to install Java Development Kit (JDK). This tutorial explains the installation procedure of Apache Ant on Ubuntu.

Installation procedure

To start the installation procedure, first update the system repositories in the target system.

root@linuxhelp1:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease

Apache Ant will require you to install Java, so make sure you have java installed on your machine.

The repositories have been successfully updated. Now download the package for Apache Ant

root@linuxhelp1:~# wget http://redrockdigimark.com/apachemirror//ant/binaries/apache-ant-1.10.1-bin.zip
--2017-04-07 15:28:26--  http://redrockdigimark.com/apachemirror//ant/binaries/apache-ant-1.10.1-bin.zip
Resolving redrockdigimark.com (redrockdigimark.com)... 119.18.61.94
Connecting to redrockdigimark.com (redrockdigimark.com)|119.18.61.94|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8824128 (8.4M) [application/zip]
Saving to: ‘ apache-ant-1.10.1-bin.zip’ 
apache-ant-1.10.1-bin.zip                     100%[===============================================================================================> ]   8.42M   434KB/s    in 36s    
2017-04-07 15:29:02 (241 KB/s) - ‘ apache-ant-1.10.1-bin.zip’  saved [8824128/8824128]

Next extract the package into /usr/local directory for the installation of apache ant.

root@linuxhelp1:~# unzip apache-ant-1.10.1-bin.zip -d /usr/local/
Archive:  apache-ant-1.10.1-bin.zip
   creating: /usr/local/apache-ant-1.10.1/
   creating: /usr/local/apache-ant-1.10.1/bin/
  inflating: /usr/local/apache-ant-1.10.1/bin/ant 
  inflating: /usr/local/apache-ant-1.10.1/bin/antRun 
  inflating: /usr/local/apache-ant-1.10.1/bin/antRun.pl 
  inflating: /usr/local/apache-ant-1.10.1/bin/complete-ant-cmd.pl 
  inflating: /usr/local/apache-ant-1.10.1/bin/runant.pl 
  inflating: /usr/local/apache-ant-1.10.1/bin/runant.py 
   creating: /usr/local/apache-ant-1.10.1/etc/
   creating: /usr/local/apache-ant-1.10.1/etc/checkdata-style/
   creating: /usr/local/apache-ant-1.10.1/lib/
   creating: /usr/local/apache-ant-1.10.1/manual/
   creating: /usr/local/apache-ant-1.10.1/manual/Integration/
   creating: /usr/local/apache-ant-1.10.1/manual/Tasks/
.
.
.
1.10.1/manual/tutorial-tasks-filesets-properties.zip 
  inflating: /usr/local/apache-ant-1.10.1/manual/tutorial-writing-tasks-src.zip
  inflating: /usr/local/apache-ant-1.10.1/manual/tutorial-writing-tasks.html 
  inflating: /usr/local/apache-ant-1.10.1/manual/tutorials.html 
  inflating: /usr/local/apache-ant-1.10.1/manual/using.html 
  inflating: /usr/local/apache-ant-1.10.1/manual/usinglist.html 
  inflating: /usr/local/apache-ant-1.10.1/patch.xml

Move to the extracted location and rename the directory.

root@linuxhelp1:~# cd /usr/local
root@linuxhelp1:/usr/local# ll
total 44
drwxr-xr-x 11 root root 4096 Apr  7 15:29 ./
drwxr-xr-x 11 root root 4096 Apr 21  2016 ../
drwxr-xr-x  6 root root 4096 Feb  2 20:00 apache-ant-1.10.1/
drwxr-xr-x  2 root root 4096 Apr 21  2016 bin/
drwxr-xr-x  2 root root 4096 Apr 21  2016 etc/
drwxr-xr-x  2 root root 4096 Apr 21  2016 games/
drwxr-xr-x  2 root root 4096 Apr 21  2016 include/
drwxr-xr-x  4 root root 4096 Apr 21  2016 lib/
lrwxrwxrwx  1 root root    9 Dec 27 15:52 man ->  share/man/
drwxr-xr-x  2 root root 4096 Apr 21  2016 sbin/
drwxr-xr-x  8 root root 4096 Apr 21  2016 share/
drwxr-xr-x  2 root root 4096 Apr 21  2016 src/
root@linuxhelp1:/usr/local# mv apache-ant-1.10.1 apache-ant

The directory has been moved and renamed. Now create the softlink using below command

root@linuxhelp1:/usr/local# ln -s /usr/local/apache-ant/ /usr/local/ant

Now create Environment Variables for Apache Ant. Create a file called ant.sh inside /etc/profile.d/ directory.

root@linuxhelp1:/usr/local# vim /etc/profile.d/ant.sh

Now add the below lines into ant.sh file. Save and exit from the file.

export ANT_HOME=/usr/local/ant
export PATH=${ANT_HOME}/bin:${PATH}

After creating environment variables, you need to run the following command to execute the variables.

root@linuxhelp1:~# source /etc/profile

The Apache Ant has been successfully installed. Next you can check the version for Apache Ant.

root@linuxhelp1:~# ant -version
Apache Ant(TM) version 1.10.1 compiled on February 2 2017

Wasn' t that an easy installation procedure? Apache Ant is a used to effectively build Java applications and it is extremely flexible.

Tag : Apache Ubuntu
FAQ
Q
What is Apache Ant used for?
A
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.
Q
What was its current release of Apache Ant? How to keep track of it?
A
The current release of Apache Ants can be found under this link "http://redrockdigimark.com/apachemirror//ant/binaries/"
Q
What is Ant in Devops?
A
Apache Ant is a software tool for automating software build processes, It was a replacement for the unix make build tool
Q
My server is Centos 7 so please provide the procedure for Apache Ant in centos 7?
A
For installing Apache Ant follow this link :https://www.linuxhelp.com/how-to-install-apache-ant-in-centos-7/"
Q
What are its basic requirement software for Apache Ant?
A
Apache Ant will require you to install Java, so make sure you have java installed on your machine.