How to Install Apache Ant on Ubuntu Linux
Apache Ant automates Java software builds on Ubuntu Linux by reading instructions from XML files to compile and test code. Setting up Apache Ant on Ubuntu version 20.04 or 18.04 saves time when you work on Java projects, and the installation takes only a few basic terminal commands to get ready for use.
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
OpenJDK 8 (a free version of the Java development kit) must be installed on your Ubuntu system before you can run Apache Ant. You can install OpenJDK 8 quickly using your terminal by running the package manager commands to download and set up the Java environment required for Ant to work properly.
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.
java -version
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 can be installed on Ubuntu using the apt package manager for a fast and straightforward setup. Running the apt update and install commands downloads Ant directly from the official Ubuntu software sources, which makes it easy to keep your build tool updated.
Run the following commands in your terminal to install Ant via apt:
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:
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
SDKMAN (a tool for managing multiple software development kits) lets you install Apache Ant and switch between different versions on Ubuntu. This method works well if you need to run multiple versions of Ant or Java on the same system without conflicts.
SDKMAN lets you manage parallel versions of multiple Software Development Kits on Unix-based systems. Setting it up takes a few terminal commands.
Setting up SDKMAN! on UNIX-like systems is quite efficient.
Run the commands below to download and install.
sudo apt install curl curl -s "https://get.sdkman.io" | 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/sdkman-init.sh"
Then issue the following command:
sdk help
Enjoy!!!
Next, please activate it.
source "$HOME/.sdkman/bin/sdkman-init.sh"
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, run the commands below to install Apache Ant.
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.
ant -version
Download and Install Ant Manually
Manual installation lets you download the latest release of Apache Ant directly from the official website without using a package manager. You download the archive file and extract it to your computer, which gives you full control over where and how Ant is placed 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.
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.
sudo nano /etc/profile.d/ant.sh
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.
source /etc/profile
You can verify the Ant version by running the commands below:
ant -version
Notice the latest version is now used?
Output:
Apache Ant(TM) version 1.10.7 compiled on September 1 2019
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 set up Apache Ant on your Ubuntu system and enhance your Java development workflow.
Was this guide helpful?
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.
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
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