May 242016

ADM

How to install Apache Ant on Mac OS X

  • 24 May 2016
  • ADM

 

 

 

How to install Apache Ant on Mac OS X - images/logos/ant.jpg

 

In this tutorial, I will show you how to install Apache Ant on Mac OS X.

For this tutorial I will use:

  • Apache Ant version 1.9.6.
  • Mac OS version 10.11.3.

Some of the Mac OS versions already have pre-installed Apache Ant. In order to check this, from terminal run the following command:

macbook:~ adm$ ant -v
-bash: ant: command not found
macbook:~ adm$

If you have a similar output you need to install Apache Ant.

Installation

Step1 - download the Apache Ant

From the download page, section Current Release of Ant, download the tar.gz version, currently version 1.9.6.

Step2 - extract it from archive

The file was downloaded in my Downloads folder. To extract from the archive run the tar command as in the following example:

macbook:Downloads adm$ pwd
/Users/adm/Downloads
macbook:Downloads adm$ tar vxf apache-ant-1.9.6-bin.tar.gz
x apache-ant-1.9.6/bin/ant
x apache-ant-1.9.6/bin/antRun
x apache-ant-1.9.6/bin/antRun.pl
x apache-ant-1.9.6/bin/complete-ant-cmd.pl
x apache-ant-1.9.6/bin/runant.pl
x apache-ant-1.9.6/bin/runant.py
x apache-ant-1.9.6/
x apache-ant-1.9.6/bin/
x apache-ant-1.9.6/etc/
x apache-ant-1.9.6/etc/checkstyle/
x apache-ant-1.9.6/lib/
x apache-ant-1.9.6/manual/
x apache-ant-1.9.6/manual/Integration/
x apache-ant-1.9.6/manual/Tasks/
x apache-ant-1.9.6/manual/Types/
x apache-ant-1.9.6/manual/api/
...............

Note: The output will be very long, so I removed it from here.

Step3 - move Ant to destination folder

I will move Ant to /usr/local/ant using the mv command:

macbook:Downloads adm$ mv apache-ant-1.9.6 /usr/local/ant
mv: rename apache-ant-1.9.6 to /usr/local/ant: Permission denied
macbook:Downloads adm$ sudo mv apache-ant-1.9.6 /usr/local/ant
Password:
macbook:Downloads adm$ 

Note: As you can see sudo need to be used.

Step4 - edit ~/.bash_profile file

In order to have Ant accessible from any folder we need to setup ANT_HOME variable and add bin folder to the PATH variable:

macbook:Downloads adm$ vi ~/.bash_profile

My /.bash_profile look like this after I added ANT_HOME and edited PATH:

export ANT_HOME=/usr/local/ant
export M2_HOME=/usr/local/maven
export PATH=$PATH:$M2_HOME/bin
export PATH=$PATH:$M2_HOME/lib

##
# Your previous /Users/adm/.bash_profile file was backed up as /Users/adm/.bash_profile.macports-saved_2013-11-17_at_23:25:14
##

# MacPorts Installer addition on 2013-11-17_at_23:25:14: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH:$ANT_HOME/bin
# Finished adapting your PATH environment variable for use with MacPorts.

export JAVA_HOME=$(/usr/libexec/java_home)

Verify

To check if Apache Ant was successful install run again the ant -v command after the terminal was restarted.

macbook:~ adm$ ant -v
Apache Ant(TM) version 1.9.6 compiled on June 29 2015
Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed
macbook:~ adm$

If you have an output similar with this you have successfully installed Apache Ant.

 

 

 

References