Follow
Ubuntu Linux

How to Install Apache Ant on Ubuntu Linux

Richard
Written by
Richard
Aug 11, 2020 Updated Mar 18, 2026 4 min read
How to Display Seconds on Ubuntu Top Menu Clock
How to Display Seconds on Ubuntu Top Menu Clock

You install Apache Ant on Ubuntu Linux to automate Java application development and build processes.

Apache Ant is an open-source build automation tool that uses XML scripts to define how your Java applications are compiled, assembled, tested, and deployed.

This guide will show you how to get Ant up and running on Ubuntu, specifically covering versions like Ubuntu 20.04 and 18.04, so you can begin streamlining your Java projects.

⚡ Quick Answer

Install Apache Ant on Ubuntu by first installing OpenJDK 8 using `sudo apt update && sudo apt install openjdk-8-jdk`. Then, install Ant using `sudo apt install ant` or manage versions with SDKMAN by running `sdk install ant`.

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:

🐧Bash / Shell
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. The output should look something like this:

💻Code
java -version
💻Code
Output:
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)

Now you’re ready to install Apache Ant.

Install Apache Ant via Apt

Apache Ant comes via Ubuntu’s default repositories. However, the version in Ubuntu’s repositories might not be the latest. If you need the most current version, you’ll have to install it manually or use external software sources (third-party repositories).

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

🐧Bash / Shell
sudo apt update
sudo apt install ant

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

💻Code
ant -version

It should output a similar line as below:

💻Code
Output:
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.

Getting SDKMAN! set up on UNIX-like systems is quite simple.

Run the commands below to download and install.

🐧Bash / Shell
sudo apt install curl
curl -s "https://get.sdkman.io" | sudo bash

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

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

    source "/home/richard/.sdkman/bin/sdkman-init.sh"

Then issue the following command:
    sdk help
Enjoy!!!

Next, please activate it.

💻Code
source "$HOME/.sdkman/bin/sdkman-init.sh"

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

💻Code
sdk version

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

💻Code
==== 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, run the commands below to install Apache Ant.

🐧Bash / Shell
sudo bash
sdk install ant

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

💻Code
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:

💻Code
ant -version

Download and Install Ant Manually

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

You can download the 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.

Command Prompt
cd /tmp
wget http://mirror.downloadvn.com/apache//ant/binaries/apache-ant-1.10.7-bin.tar.gz
sudo tar -xf apache-ant-1.10.7-bin.tar.gz -C /usr/local

This command extracts the Ant files into the /usr/local/apache-ant-1.10.7 directory.

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

🐧Bash / Shell
sudo ln -s /usr/local/apache-ant-1.10.7/ /usr/local/ant

After that, create an Ant executable shell script file at the /etc/profile.d folder.

🐧Bash / Shell
sudo nano /etc/profile.d/ant.sh

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

💻Code
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.

💻Code
source /etc/profile

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

💻Code
ant -version

Notice the latest version is now used?

💻Code
Output:
Apache Ant(TM) version 1.10.7 compiled on September 1 2019

Conclusion:

In summary, installing Apache Ant on Ubuntu is a process that allows Java developers to automate their application development tasks effectively. Here are the key points to remember:

  • Apache Ant is a powerful tool for compiling, assembling, testing, and running Java applications.
  • You can install Apache Ant through various methods, including:
    • Using Apt from the default Ubuntu repositories.
    • Using SDKMAN, which offers a convenient way to manage multiple software development kits.
    • Manually downloading and installing Ant from the Apache Ant website for the latest version.
  • Ensure you have OpenJDK installed, as it is a prerequisite for running Apache Ant.
  • After installation, verifying the version of Apache Ant is essential to confirm successful setup.

By following these steps, you can efficiently set up Apache Ant on your Ubuntu system and enhance your Java development workflow.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04
How to Install i-doit on Ubuntu with Apache
CMS How to Install i-doit on Ubuntu with Apache

0 Comments

  • 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

    Reply
    • Simon Watson

      this looks to have been fixed as of 1.10.8 on March 22 2021:
      ls /usr/share/ant/bin
      ant antRun antRun.pl complete-ant-cmd.pl runant.pl

      Reply

Leave a Comment

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