How to install Ant on Linux

· Java, Linux
Author

In this article we’ll show how to install Ant on Linux. Ant is one of the most popular (though certainly not the only) build tool for Java programming, and once your Java development project reaches a certain complexity it’s bound to need Ant. Most distributions have some version of Ant included, but it’s often outdated and set to use some distribution-specific version of Java that’s not 100% ok.

So instead we’ll show how to install Ant from scratch, which is really quite easy.

Requirements

This article requires basic Linux command line skills. Additionally we’ll assume that you have Java installed somehow and are happy with that version. If you don’t know which version you have you can try it out with:

java -version

Installation steps

Download the current release of Ant from the official site in .tar.gz format. Here we’ll use /usr/java as the installation location, but you can put it in any directory where your user has write permissions.

mv apache-ant*.tar.gz /usr/java
cd /usr/java
tar xzf apache-ant*.tar.gz
rm apache-ant*.tar.gz
apache-ant-*/bin/ant -version

If this doesn’t produce errors and the last command above shows the version of Ant (e.g. “Apache Ant(TM) version 1.8.4 compiled on May 22 2012”) you’re set.

If the ant command cannot find Java you should run:

export JAVA_HOME=/path/to/java/install/directory

Note that we didn’t add Ant to the shell path yet. You can do so if you want, but in my opinion it’s better to explicitly run

/usr/java/apache-ant-*/bin/ant

because that way it will be clearer which version of Ant you are using.

1 Comment

Comments RSS
  1. Mrunali

    use “sudo” before “mv …” if you get permission denied.You will need the password then.
    If you get java as an archive file in /usr instead of “apache-ant…” then do “tar xvf java”
    and laler also do “rm java” instead of ” rm apache..”.

Leave a Comment