Setup Apache Ant on Mac

Apache Ant is Java library and command line tool used to “build” or run tasks. It’s pretty popular in the Java Community along with Maven. We don’t typically use Ant in our day to day build process for projects at Linchpin but we recently became involved in a project that does require it.

Below is a breakdown on how to get ant going on your mac. I am using El Capitan and installing Apache Ant on a mac is pretty straight forward.

I’m savvy and hate reading version.

  1. Download and extract the latest stable build (zip or tar.gz)
  2. After extraction rename the directory to “ant” and move it to your User’s home holder
  3. Add /Users/[username]/ant/bin to your .bash_profile
  4. Away you go.

I’d like a guided tour to get going.

You will need to make use of terminal for this to go efficiently.

  1. Download the latest stable build (zip or tar.gz)
  2. Extract the .zip or un tar.gz into move into your home directory or extract it using finder and drag into your User’s Home (~) folder.


    tar xvfz apache-ant-1.9.7-bin.tar.gz

    In the code above the xvfz portion is a bunch of switches/options. The z switch is telling the command to unzip.

  3. Once extracted I prefer to rename the folder to “ant” vs having the the version number at it will make it easier regarding updates later on.
  4. Next up we need to add ant to our path within our .bash_profile so it can run by simply using the “ant” command within terminal.If you are like me. You may not have had a “.bash_profile” file. To check if you do it’s really easy
  5. Open Terminal (if you don’t already have it open)
    When opening terminal will typically use your user folder as the current directory.
    To confirm use the following command to change directory to your home ~

    cd ~
  6. List our files in our home directory and look for .bash_profile
    ls -a

    If you do not have the .bash_profile we need to create one. If you already have a .bash_profile skip to step 8** 

  7. We can create a .bash_profile from terminal as well. Below we create a new bash profile and also open it in text edit with 2 simple commands
    touch ~/.bash_profile
    open -e ~/.bash_profile
  8. With our new .bash_profile file open. Let’s add in our Apache Ant path. This is an important step so we can call our ant command in terminal easily. If you recall from previous steps we extracted Ant and renamed the folder to “ant” we then moved the ant folder into our user home directory. If you still have terminal open we can easily get the full path for our ant folder.If you aren’t familiar with linux terminal commands. It can be a bit concerning if you see something like “pwd” at first in a command. Don’t worry this command simply means “print working directory” after we’ve change the directory we’re working in.
    cd ~/ant/bin

    Upon running the command you should see terminal spit out something similar to this…

  9. Copy the path to your clipboard so we can paste it into the .bash_profile we created a little while ago
  10. Go back to your open text editor.
    Now we will either add the new directory to your existing PATH or we will create a new “export”.
    If you needed to create the .bash_profile file earlier, you’ll want to implement the code below. Remember this is just an example and your path should have your username and not mine.

    export PATH=${PATH}:/Users/aware/ant/bin

    If you already had an existing .bash_profile file, you will need to add the ant path to your PATH. Luckily this is pretty easy to do. If you already had something similar to the following we can add in our new directory to the end of the existing paths by using a colon (:) as a delimiter and pasting our ant directory from our clipboard to the end of the export PATH.

    export PATH=${PATH}:usr/local/bin:/Users/aware/ant/bin

    Save the file and we’re almost done.

  11. Lastly we need to execute the command to make sure bash knows our profile is updated.
    cd ~
    . .bash_profile

There you have it. We’ve now added ant to our system and we can run builds!


About The Author

Aaron Ware

Over the past decade Aaron Ware has worked with leading brands, start-ups and everyone in between to develop innovative, highly interactive, feature-rich websites and online apps.

| @aaronware