How to install Apache Ant on CentOS

Apache Ant is an open-source tool for automating Java program build process. Similar to how the make utility builds an executable from source code and libraries using a Makefile, Apache Ant builds a Java project from its source code and libraries by using a similar XML file.

If you would like to install Apache Ant on CentOS, follow this guideline.

First of all, you need to install Java Development Kit, since Apache Ant will use JDK during its build process.

Then go ahead and install Apache Ant, using its binary distribution from the official Apache web site.

$ wget http://www.us.apache.org/dist/ant/binaries/apache-ant-1.9.2-bin.tar.gz
$ sudo tar xvfvz apache-ant-1.9.2-bin.tar.gz -C /opt
$ sudo ln -s /opt/apache-ant-1.9.2 /opt/ant

You then have to set up ANT_HOME environment variable, and include Ant binary in your path, as follows.

$ sudo sh -c 'echo ANT_HOME=/opt/ant >> /etc/environment'
$ sudo ln -s /opt/ant/bin/ant /usr/bin/ant

Log out and log back in, to reload the environment variables defined in /etc/environment.

Finally, verify that Apache Ant is successfully installed.

$ ant -version
Apache Ant(TM) version 1.9.2 compiled on July 22 2013

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

3 thoughts on “How to install Apache Ant on CentOS

  1. I had to modify java.sh to include the following line:
    export PATH=$JAVA_HOME/bin:$PATH

    Otherwise ant was reporting:
    Error: JAVA_HOME is not defined correctly.
    We cannot execute /usr/local/jdk/bin/java

Leave a comment

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

Current ye@r *