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 that has number of built-in tasks allowing to compile, assemble, test and run Java applications. If you’re going to be developing Java apps, you may need Apache Ant to help automate the process.
For student or new user looking for a Linux system to learn on, the easiest place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners.
Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other device.
While learning Ubuntu, you will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to using the system to get work done.
To get started with installing Apache Ant on Ubuntu, please follow the steps below:
Step 1: Install OpenJDK 8
Apache Ant is a Java based app so you’ll need Java installed. First, download the Java 8 Development Kit: either the official Oracle JDK or Open JDK
For this tutorial, we’re going to be 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:
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)
After, continue below to install Apache Ant.
Step 2: Install Apache Ant via Apt
Apache Ant comes via Ubuntu default repositories. However, the version with comes with Ubuntu repositories might not be the latest version. If you wish 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 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
Option 2: Install Apache Ant using SDKMAN
You can also install Apache Ant via 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 as 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, activate it
source "$HOME/.sdkman/bin/sdkman-init.sh"
Lastly, run the following code snippet to ensure that installation succeeded:
sdk version
If all went 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 similar message as below:
Installing: ant 1.10.1 Done installing! Setting ant 1.10.1 as default.
When finishes, you can verify whether Ant is installed successfully or not by checking its version:
ant -version
Option 3: Download and Install Ant Manually
If you want to manually download and install Apache Ant yourself, 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 it.
cd /tmp wget 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 a ant.sh file at /etc/profile.d folder.
sudo nano /etc/profile.d/ant.sh
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 Ant version by running the commands below:
ant -version
Notice a latest version is now used?
Output:
Apache Ant(TM) version 1.10.7 compiled on September 1 2019
Conclusion:
This post showed you how to install Apache Ant on Ubuntu 20.04 | 18.04. If you find any error above, please use the comment form below to report it.
Thanks,
You may also like the post below: