Skip to content
Follow
Ubuntu Linux

How to Install Apache Ant on Ubuntu Linux

Richard
Written by
Richard
Aug 11, 2020 Updated Jul 14, 2026 5 min read
How to Display Seconds on Ubuntu Top Menu Clock
How to Display Seconds on Ubuntu Top Menu Clock

Installing Apache Ant on Ubuntu Linux automates your Java development tasks.

Apache Ant is a free tool that helps build Java programs automatically. It reads special instructions written in XML files to know how to compile, test, and prepare your Java applications.

You can install Apache Ant on Ubuntu versions like 20.04 or 18.04 to make building your Java projects much faster and simpler.

⚡ 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

To run Apache Ant, you need Java installed on your Ubuntu system. The most direct way to get a compatible version is by installing OpenJDK 8 using your terminal. This method is quick and works well with Ant, so you can get it set up in just a few commands.

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

To do that, run the commands below:

After installing Java, verify the installation with the commands below. Look for output similar to version information for Java 11 or a later version.

💻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

The most convenient way to install Apache Ant on Ubuntu is by using the apt package manager. This installs Ant directly from Ubuntu’s software sources, making it fast and efficient to set up and keep updated. You can install Apache Ant using apt-get with two commands in your terminal.

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

Apache Ant helps you manage different Java versions on your Ubuntu system. To install Ant using SDKMAN, a tool that manages software development kits for at least 100 different tools, you first set up SDKMAN on Ubuntu. You can then use SDKMAN to easily switch between Ant versions.

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.

Setting up SDKMAN! on UNIX-like systems is quite efficient.

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:

You can verify whether Apache Ant is installed successfully by checking its version. To do this, open your command line and type `ant -version`. If Apache Ant is correctly installed, you will see output showing the Ant version, such as Apache Ant version 1.10.13.

💻Code
ant -version

Download and Install Ant Manually

You can download and install the absolute latest version of Apache Ant manually if you prefer not to use package managers. This method involves getting the Ant files directly from the Apache website. You will download the Ant distribution and then extract the files to get it set up on your system.

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.

Create an Ant executable shell script file in the `/etc/profile.d` folder. This sets up Ant’s environment variables, ensuring Ant is available system-wide after you log in.

🐧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.

💡Tip
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 Apache on Ubuntu Linux
Ubuntu Linux How to Install Apache on Ubuntu Linux
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 Set Up Environment Variables in Windows 11
Windows How to Set Up Environment Variables in Windows 11

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 *