How to Install Apache Ant on Ubuntu Linux
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.
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:
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:
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 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:
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
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.
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+362After 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:
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, 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.
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.
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.
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.
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?
Output:
Apache Ant(TM) version 1.10.7 compiled on September 1 2019Conclusion:
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?
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