How to install apache ant 1.10.3 on Ubuntu 18.04

To install Apache Ant 1.10.3 on Ubuntu   18.04

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

Let’ s First start with updating the system repository. 

root@linuxhelp:~# apt-get update 
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu bionic InRelease 
Hit:3 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done

After updating the system repository proceed to download apache-ant  latest version

root@linuxhelp:~# wget http://www-eu.apache.org/dist//ant/binaries/apache-ant-1.10.3-bin.zip
--2018-04-30 18:42:39--  http://www-eu.apache.org/dist//ant/binaries/apache-ant-1.10.3-bin.zip
Resolving www-eu.apache.org (www-eu.apache.org)... 195.154.151.36, 2001:bc8:2142:300::
Connecting to www-eu.apache.org (www-eu.apache.org)|195.154.151.36|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9011568 (8.6M) [application/zip]
Saving to: ‘ apache-ant-1.10.3-bin.zip’ 

apache-ant-1.10.3-bin.zip      100%[===================================================> ]   8.59M  38.7MB/s    in 0.2s    

2018-04-30 18:43:02 (38.7 MB/s) - ‘ apache-ant-1.10.3-bin.zip’  saved [9011568/9011568]

After Downloading unzip the package to /usr/local directory.

root@linuxhelp:~# unzip apache-ant-1.10.3-bin.zip -d /usr/local/
Archive:  apache-ant-1.10.3-bin.zip
   creating: /usr/local/apache-ant-1.10.3/
   creating: /usr/local/apache-ant-1.10.3/bin/
  inflating: /usr/local/apache-ant-1.10.3/bin/ant  
  inflating: /usr/local/apache-ant-1.10.3/bin/antRun  
  inflating: /usr/local/apache-ant-1.10.3/bin/antRun.pl  
  inflating: /usr/local/apache-ant-1.10.3/bin/complete-ant-cmd.p
.
.
  inflating: /usr/local/apache-ant-1.10.3/manual/tutorial-writing-tasks-src.zip  
  inflating: /usr/local/apache-ant-1.10.3/manual/tutorial-writing-tasks.html  
  inflating: /usr/local/apache-ant-1.10.3/manual/tutorials.html  
  inflating: /usr/local/apache-ant-1.10.3/manual/using.html  
  inflating: /usr/local/apache-ant-1.10.3/manual/usinglist.html  
  inflating: /usr/local/apache-ant-1.10.3/patch.xml  

Now navigate to the extracted directory and rename the file. 

root@linuxhelp:~# cd /usr/local/ 
apache-ant-1.10.3  bin  etc  games  include  lib  man  sbin  share  src
root@linuxhelp:/usr/local# mv apache-ant-1.10.3 apache-ant
root@linuxhelp:/usr/local# ls
apache-ant  bin  etc  games  include  lib  man  sbin  share  src

Next, create a soft link using the following command.

root@linuxhelp:/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@linuxhelp:/usr/local# vi /etc/profile.d/ant.sh
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@linuxhelp:/usr/local# source /etc/profile

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

root@linuxhelp:/usr/local# ant -version
Apache Ant(TM) version 1.10.3 compiled on March 24 2018 

With this, the method to  install Apache Ant   1.10.3 on Ubuntu 18.04 comes to an end. 

Comment
gilbertoluismorillo
Jan 22 2020
Hello, i just installed the newest version 1.10.7 but when i run the ant -v command this is the output:
"Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed"
I then tried to locate that build.xml file with ant -find build.xml and couldnt find it.
Any help will be much appreciated!
Add a comment
FAQ
Q
how to check the version of apache ant?
A
use the folowing command to check the version of apache ant
# ant -version
Q
If its possible to install Apache Ant on CentOS?
A
yes, apache ant is avaialble on centos alos
refer the below link for installation
https://www.linuxhelp.com/how-to-install-apache-ant-in-centos-7/
Q
where i can create the environment variables for apache ant?
A
create Environment Variables for Apache Ant by below command
# vi /etc/profile.d/ant.sh
Q
what to do after creating the environment variables of apache ant?
A
After creating environment variables, you need to run the following command to execute the variables.
# source /etc/profile
Q
where to download the apache ant package?
A
Download the apache ant package by following link
#wget http://www-eu.apache.org/dist//ant/binaries/apache-ant-1.10.3-bin.zip