How to Install Apache Ant on Ubuntu Linux



This tutorial provides a step-by-step guide on how to install Apache Ant, a Java library and tool that automates the process for compiling, testing, and running Java applications, on Ubuntu 20.04 | 18.04. Ways to install include via Apt, SDKMAN, or manual download; associated steps each method entails, such as installing Java through OpenJDK, creating…

This brief tutorial shows students and new users how to install Apache Ant on Ubuntu 20.04 | 18.04.

Apache Ant is a Java library and tool with several built-in tasks allowing one to compile, assemble, test, and run Java applications. You may need Apache Ant to help automate the process if you’re developing Java apps.

Installing Apache Ant on Ubuntu Linux can be helpful if you’re a Java developer and want to automate the process of compiling, assembling, testing, and running Java applications.

Apache Ant provides several built-in tasks that can help you with these tasks. Ubuntu Linux is a great operating system for beginners looking to learn Linux and is one of the most accessible places to start.

Following the steps outlined in the tutorial, you can easily install Apache Ant on your Ubuntu Linux system and start automating your Java development tasks.

To get started with installing Apache Ant on Ubuntu, please follow the steps below:

Install OpenJDK 8

Apache Ant is a Java-based app, so you’ll need Java installed. First, download the Java 8 Development Kit: the official Oracle JDK or Open JDK.

For this tutorial, we’re going to install OpenJDK.

To do that, run the commands below:

sudo apt update
sudo apt-get install openjdk-8-jdk openjdk-8-doc openjdk-8-jre-lib

After installing Java, you can verify it by running the commands below:

java -version

It should output something similar, as shown below:

openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

After, continue below to install Apache Ant.

Install Apache Ant via Apt

Apache Ant comes via Ubuntu default repositories. However, the version with Ubuntu repositories might not be the latest. To install the latest, you may have to install it manually or via third-party repositories.

To install Apache Ant using apt-get, simply execute the following commands:

sudo apt update
sudo apt install ant

To verify if Ant is installed, use the commands below:

ant -version

It should output a similar line as below:

Apache Ant(TM) version 1.10.5 compiled on March 28 2019

That’s how to install Apache Ant via Apt-get

Install Apache Ant using SDKMAN

You can also install Apache Ant via the SDKMAN tool.

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 commands below to download and install.

sudo apt install curl
curl -s "" | sudo bash

After installing, you should see an output similar to the one below:

All done!
Please open a new terminal, or run the following in the existing one:

    source "/home/richard/.sdkman/bin/"

Then issue the following command:
    sdk help

Next, please activate it

source "$HOME/.sdkman/bin/"

Lastly, run the following code snippet to ensure that the installation succeeded:

sdk version

If all goes well, the version should be displayed. Something like:

==== BROADCAST =================================================================
* 2020-03-18: Gradle 6.3-rc-3 released on SDKMAN! #gradle
* 2020-03-17: Gradle 6.3-rc-2 released on SDKMAN! #gradle
* 2020-03-16: Leiningen 2.9.3 released on SDKMAN! #leiningen
SDKMAN 5.7.4+362

After installing SDKMAN, simply run the commands below to install Apache Ant.

sudo bash
sdk install ant

After installing, it should output a similar message as below:

Installing: ant 1.10.1
Done installing!
Setting ant 1.10.1 as default.

When finished, you can verify whether Ant is installed successfully or not by checking its version:

ant -version

Download and Install Ant Manually

If you want to download and install Apache Ant yourself manually, simply follow the steps below:

You can download Ant distribution from the Apache Ant website. Currently, the latest release of Ant is version 1.10.7.

To download, run the commands below, then extract them.

cd /tmp
sudo tar -xf apache-ant-1.10.7-bin.tar.gz -C /usr/local

The above command will unpack the Ant distribution to /usr/local/apache-ant-1.10.7

Next, create a symbolic link to the Ant distribution by running the commands below.

sudo ln -s /usr/local/apache-ant-1.10.7/ /usr/local/ant

After that, create an ant. sh, file at /etc/profile.d folder.

sudo nano /etc/profile.d/

Please copy and paste these lines into the file and save it.

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

Save the file and exit.

After that, run the command below to activate the above environment variables.

source /etc/profile

You can verify the Ant version by running the commands below:

ant -version

Notice the latest version is now used?

Apache Ant(TM) version 1.10.7 compiled on September 1 2019


This post showed you how to install Apache Ant on Ubuntu 20.04 | 18.04. If you find any error, please report it in the comment form below.


You may also like the post below:

Like this:

2 responses to “How to Install Apache Ant on Ubuntu Linux”

  1. Bruce Sherwood Avatar
    Bruce Sherwood

    Ubuntu 20.04 places the actual code in a different location, but links the /bin/ant link to an invalid location.

    as of 11/19/2020;
    APT will install version 1.10.7 in /usr/share/share/ant

    To fix the bad link:

    cd /bin
    sudo rm ant
    ln -s /usr/share/ant/bin/ant ant

    This builds a new soft link to the correct location

    1. Simon Watson Avatar
      Simon Watson

      this looks to have been fixed as of 1.10.8 on March 22 2021:
      ls /usr/share/ant/bin
      ant antRun

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.