Installation of Ant on OS X
Thursday, May 18th, 2006 | Journal
Tags: ant, apple, osx
Recently at work, I had to perform the task of setting up Ant on my PowerBook, and I was not satisfied with the tutorials I found online. When I finished setting up everything, I wanted to record the entire procedure for my own sake and also for people who need it. At this point, if you don’t know what is Ant, you can probably stop reading further. Most likely you will not need the knowledge that I am about to share. Of course, if you already know how to do this, then please don’t waste your time.
Before I get into step-by-step instruction, you need to download Ant. and I am assuming you saved it on your desktop. Next, open you Terminal and type the following commands:
- cd ~/Desktop
- sudo sh
- mv apache-ant-1.6.5-bin.zip /usr/local/
- cd /usr/local/
- unzip apache-ant-1.6.5-bin.zip
- chown (your account name):(your account name) apache-ant-1.6.5
- ln -s apache-ant-1.6.5 ant
Now, let me explain what each line of command means:
- Navigate to the Desktop folder where you saved the zip file.
- Authenticate as root/superuser, you will need to type your password to complete the authentication.
- Move the Ant zip file to the directory /usr/local.
- Navigate to directory /usr/local. You can execute ls command to list the content of the current directory just to verify the zip file is here.
- Unzip the zip file (pretty obvious).
- Change the ownership of the expanded directory to your regular account, so in the future you can modify the Ant folder without authenticating as root again.
- Create a link or alias, this step is optional. After the creation of this link, you can refer to Ant directory as /usr/local/ant, instead of /usr/local/apache-ant-1.6.5.
To test whether everything was done correctly, you can open a new Terminal window, and type /usr/local/ant/bin/ant. You should be able to execute Ant if everything is correct. Last thing we need to do is to set up our account so we can simply type Ant instead of this long command. After all, we are all too lazy to type few more characters.
Assuming the default shell of your Terminal is bash; make sure the following lines are in the bashrc file. You can find the file under /etc.
- export ANT_HOME=/usr/local/ant
- export PATH=${PATH}:${ANT_HOME}/bin
That’s it. To test it, quit all your Terminal windows, and then re-open a new one, type ant, you should see an error message complaining that build.xml does not exist. Done! I hope this is helpful to someone.
May 26, 2006
2:43 pm on Friday
hey, i stumbled apon your page because I was trying to install Ant on my mac with almost zero knowledge of unix admin commands. This was very helpful not only in Ant installation but it also made it easier for me to install other things. thanks! By the way, I love your blog layout ^_^
May 28, 2006
10:07 am on Sunday
Thanks for the help.
I took a slightly different route. Instead of keeping ant in the /usr/local/bin directory and making a symlink to the ant folder I kept ant in the /sr/local/apache-ant-1.6.5 directory. Then I used ln -fis to the ant binary. I got an error “Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher”. I check your site and then added the ANT_HOME to the /etc/profile file. This fixed the issue. The reason I modified profile instead of bashrc was to make ant available to all users on the system. ;-)
September 07, 2006
6:09 pm on Thursday
Thank you. This was very helpful.
September 08, 2006
2:01 pm on Friday
Sure, I am glad it’s helpful to you.
November 12, 2006
11:33 am on Sunday
Thank you for this tutorial. It has helped a lot. The only part I am stuck on is editing the “bashrc” file in /etc directory? I cannot find this file. There is a /etc directory under apache-ant-1.6.5 but only contains a variety of .xls files. (none of which is named bashrc).
Can you clarify exactly where /etc is and if I’m in the right directory? if I navigate in Terminal to /etc and type ls, the bashrc file is listed.
Thanks for your time.
November 13, 2006
6:42 pm on Monday
Hi Chris, I think you are right. Just open the Terminal and navigate to /etc and file bashrc should be in there. I hope this clarifies your confusion.
November 20, 2006
12:47 pm on Monday
Great tutorial, thanks! You saved me a lot of time.
December 26, 2006
9:33 pm on Tuesday
YOU ARE INCREDIBLE! Thanks for the great tutorial — def bookmarking this for the future.
January 23, 2007
6:35 pm on Tuesday
Great tutorial, so simple once you have the 7 steps.
January 23, 2007
11:01 pm on Tuesday
I am glad to hear that my little tutorial helped you guys.
March 19, 2007
9:33 pm on Monday
Yup, total lifesaver. I banged my head enough times with all the other stuff so this saved my head a few bumps. My head thanks you!
March 20, 2007
9:35 am on Tuesday
Hahaha, Kalli, then I am glad to save your head from bruises.
March 27, 2007
12:13 pm on Tuesday
You helped me. Thanks!
April 01, 2007
5:15 pm on Sunday
Good tutorial! Thanks for helping us out!
April 07, 2007
9:50 pm on Saturday
amazing.
this helped me to save hours on the installation
April 08, 2007
1:28 pm on Sunday
You guys are welcome!
April 19, 2007
8:17 pm on Thursday
Err, why not just install the Xcode Tools from CD1 of your OSX installation media? No downloading/untarring necessary and it’s much more likely to work with the rest of the java environment.
April 20, 2007
7:47 am on Friday
I am not aware that Xcode comes with Ant.
April 26, 2007
7:19 pm on Thursday
It does, but it may not be the latest version.
May 20, 2007
10:45 am on Sunday
works. thanks!
May 22, 2007
6:15 am on Tuesday
Nothing isn’t understandable. Why your are write the tutorials cutted from the context? You should write more detailed tutorials because there are very much steps you didn’t mentioned. There are some exact string has to be written in command prompt. I’m new in using of Ant. This short information can be usefull for programmerg to refresh their information about installing but not to learn this process. !!!
May 22, 2007
11:26 am on Tuesday
Of course, my intention is to write a complete tutorial with every step of the installation mentioned and possibly explained. That’s the reason why I listed all the steps and then explained each steps in plain English. If there is anything missing from my tutorial, please let me know; but as far as I know, I think this tutorial is pretty complete.
June 04, 2007
10:01 pm on Monday
Thanks for the tutorial. I’m a Windows user switching to a Mac so this helped save me a lot of time!
June 09, 2007
2:13 pm on Saturday
Hi, awesome tutorial but I have a question. When I try to edit the bashrc file, it says that it’s read-only and the overwrite doesnt work. I’m totally new to mac so I guess that might be a stupid question. thanks for the tutorial and your site is realy neat.
June 16, 2007
9:27 pm on Saturday
It worked! Thanks!
June 25, 2007
8:09 am on Monday
/etc/bashrc needs to be edited as root:
sudo vi /etc/bashrc
Better yet use the specific users bash config file:
vi ~/.bashrc
That way changes are local to the individual user
July 12, 2007
2:34 pm on Thursday
Thank you! Very helpful!
July 13, 2007
11:11 pm on Friday
Hello –
I think I followed the procedure carefully but I still get this error message:
Buildfile: build.xml does not exist!
Build failed
Please help.
Dennis
July 15, 2007
4:24 pm on Sunday
Hi Dennis, if you are getting that message it means Ant is successfully installed, but in the current directory there is not a legit Ant build file.
July 22, 2007
2:16 pm on Sunday
it works! ooohhh yeaah
August 19, 2007
9:17 pm on Sunday
Thank you so much for the Tutorial, it worked just fine, except that for the chown command I used:
chown
October 11, 2007
9:28 am on Thursday
Nice Tutorial. Saved me time.
November 01, 2007
8:27 pm on Thursday
thank you, this made the process a painless experience if only all tutorials were this good we would all be out of a job :)
November 04, 2007
9:57 pm on Sunday
thanks!!! it helped a lot!!
November 04, 2007
10:54 pm on Sunday
I am glad to see more people got helped from this little tutorial!
November 11, 2007
4:34 pm on Sunday
I’ve downloaded Ant onto my desktop. It is not a zip and it’s version 1.7.0
users-computer:~/Desktop user$ sudo sh
Password:
sh-1.23a# mv apache-ant-1.7.0 /usr/local/
sh-1.23a# cd /user/local
sh: cd: /user/local: No such file or directory
sh-1.23a#
I’ve modified the sh to 1.23a# for this posting because I don’t know what 1.23a# is revealing, if anything, about my password.
I don’t seem to be getting anywhere. Any idea what I am doing wrong?
November 11, 2007
5:48 pm on Sunday
I goofed above with user rather than usr but I am not out of the woods yet.
I am not sure I understand the verification:
users-computer:~ user$ /usr/local/ant/bin/ant
-bash: /usr/local/ant/bin/ant: No such file or directory
users-computer:~ user$ cd /usr/local/ant/bin/ant
-bash: cd: /usr/local/ant/bin/ant: No such file or directory
users-computer:~ user$
Where do I go from here?
November 12, 2007
12:41 am on Monday
Hi Lindsey! If you followed my tutorial correctly, I believe your ANT is already installed successfully. To verify its installation, simply open up Terminal and type “ant”, do you get something like this “Buildfile: build.xml does not exist!”? If you do, your ANT is installed successfully. Let me know how the verification goes.
November 18, 2007
1:15 pm on Sunday
Thanks, helped me.
November 26, 2007
8:47 pm on Monday
Hi !
My Mac said:
sh-2.05b# /usr/local/ant/bin/ant
java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/AntMain
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
……..
Why ? Please help me!
November 26, 2007
10:53 pm on Monday
Hi snaf_mocha! I am not 100% sure why you are getting that error, how about try everything from the start.
December 18, 2007
10:02 am on Tuesday
Amazing Tutorial. You are a life saver! Dropping to terminal is always a fight of some sort. As a note to anyone else. If you get
“sudo: /private/etc/sudoers is mode 0644, should be 0440”
Just open “Disk Utility” and “Repair Disk Permissions” Some reason mine were off. Thanks again.
January 13, 2008
4:59 pm on Sunday
Thanks !!
February 18, 2008
4:16 am on Monday
Thank you =)
February 22, 2008
10:36 am on Friday
Hi. If you have an existing installation of older ant, then it’s most likely a symlink /usr/bin/ant. You may want to do:
su bash
cd /usr/bin
rm ant
ln -s /usr/local/ant/bin/ant
February 27, 2008
4:42 am on Wednesday
Nice! Great guide. It got me setup in 5 mins flat! Gj!!
March 17, 2008
10:32 am on Monday
If you are using Leopard, just install the XCode tools
ant is installed to /usr/share/ant – version 1.7.0
just set ANT_HOME to point to this.
it also installs the following tools
maven /usr/share/maven – version 2.0.6
Junit /usr/share/junit – Version 4.1
it also installs cvs (1.2.6) and subversion (1.4.4)
So you dont need to do anything other than setup the home directory exports.
March 17, 2008
2:42 pm on Monday
Thanks Tim for the Leopard setup tip!
April 03, 2008
12:44 pm on Thursday
I want to make love to this tutorial…slowly. You pwn dude!
April 21, 2008
5:59 pm on Monday
Thanks !
May 29, 2008
1:18 pm on Thursday
Thank you, very helpfull. I’m new to macs and this osx ant tutorial is awesome :)
June 11, 2008
7:39 pm on Wednesday
this helped me also, any clue how to get junit (which is in /usr/share/junit ) to be associated with ant? I am running OS X 10.5.3, but the ant installation in /usr/share/ant is 1.6.5
In my case I was trying to get version 1.7.0 installed which worked, a hint to discern the version is to type
ant -version
which will return:
Apache Ant version 1.6.5 compiled on December 25 2005
August 13, 2008
8:33 am on Wednesday
Hi, great page and easy to use. Thanks.
September 01, 2008
10:47 am on Monday
where is the etc directory? I only see it under ANT, but not for terminal – this must be the wrong place…
October 01, 2008
1:49 am on Wednesday
Excellent, perfect instructions for the job, got me up and running in no time at all.
October 07, 2008
7:44 am on Tuesday
If you install the Fink package manager, it’s as simple as “fink install ant”.
You can then browse the other packages, such as ant-junit, etc.
Of course, if you don’t want to install a package manager, the above instructions are gold.
October 23, 2008
5:29 pm on Thursday
Thanks! I just started coding in Java, and have not yet built anything (I have been running all my source within my Eclipse IDE). This was very helpful and straightforward.
November 04, 2008
10:29 am on Tuesday
Thanks, AsceticMonk. This is exactly what I needed. Surprised the install process is still the same 2 1/2 years later. Cheers!
November 04, 2008
2:11 pm on Tuesday
You are welcome Jason!
November 18, 2008
1:57 pm on Tuesday
Hello I need to use ant 1.7.1
if I follow your tutorial it doesn´t overwrite my
ant 1.7.0 which was already installed, do I need to delete it first?
I´m using Leopard 10.5.5 with a bash, does anybody have a soulution for it?
My other question is, I don´t recieve anything when I do an
echo $ANT_HOME on a bash, althought I´ve exportet the variable
ANT_HOME at
.bashrc
simply with
pico .bashrc
do I have to put this into the .profile?
greetings from berlin ;)
November 20, 2008
1:38 pm on Thursday
Hi muris, since you had Ant 1.7.0 installed, you should already have ANT_HOME set, you just need to update it so it points to the latest Ant version.
February 12, 2009
4:06 pm on Thursday
Thank you for the great work in providing this step-by-step guide with clear and concise explanation. Best wishes!
February 18, 2009
7:11 am on Wednesday
for those of you who already have ant installed but don’t know where it is (like me) use these command lines in Termial:
$ which ant
and to find out version:
$ ant -version
June 24, 2009
12:28 am on Wednesday
Thx for that!
however I am still gettn the following error when I deploy ant
Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
[taskdef] Could not load definitions from resource ise/antelope/tasks/antlib.xml. It could not be found.
anyone have a solution??
April 30, 2009
6:13 pm on Thursday
Thanks! I needed to upgrade to ANT 1.7 to try out Selenium Grid. Your instructions worked like a snap :-)
http://twitter.com/JonKernPA
May 01, 2009
12:21 pm on Friday
You are welcome Jon! I am glad this entry is still helping people to this date.
August 24, 2009
2:11 am on Monday
Hi
When i m running the build.xml inside Eclipse 3.4 in mac OSX, getting-BUILD FAILED
XML parser factory has not been configured correctly: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found
Please let me know what needs to be done
August 24, 2009
11:49 pm on Monday
Seems to me you are trying to do something in your code using JAXP, do you have that installed properly? It’s not a problem from ANT.
August 26, 2009
8:53 pm on Wednesday
thanks
I fixed this issue.it seems be some config issue with my leopard model
October 01, 2009
2:28 pm on Thursday
I running snow leopard and on this system there is no directory withe the name /usr/local. So how can I get it running on this OS X version?
Thanx,
Ivo Trompert
October 19, 2009
8:11 am on Monday
Worked like a charm, thanks!
October 25, 2009
9:04 pm on Sunday
hello I am new to terminal and cannot figure out what to put in the fields of (your account name)
chown (your account name):(your account name) apache-ant-1.6.5
I have tried putting my account name in every way imaginable. Can someone Please help me out??
December 06, 2009
4:54 pm on Sunday
Perfect steps! Worked like a charm.
February 25, 2010
5:44 am on Thursday
God send!! Thank you so much!
April 20, 2010
5:17 am on Tuesday
Just a quick thanks. Brilliant helper
June 06, 2010
3:17 am on Sunday
Great tutorial. Thank you very much!!!
June 09, 2010
12:35 am on Wednesday
4 years after it still works very well ! nice thanks a lot
September 17, 2010
12:52 pm on Friday
Thanks for the help, definitely works like a charm.
I am trying to build an Android app on OS X 10.4.11. While trying to compile my project I run into the following error:
-resource-src:
[echo] Generating R.java / Manifest.java from the resources…
[null] dyld: Symbol not found: _open$UNIX2003
[null] Referenced from: /android/platforms/android-8/tools/aapt
[null] Expected in: /usr/lib/libSystem.B.dylib
[null]
BUILD FAILED
/android/tools/ant/ant_rules_r3.xml:283: null returned: 133
I’ve researched around and not really sure what to do. Any ideas? (FYI, I am a novice at the UNIX IDE).
September 27, 2010
4:19 am on Monday
Just found out that Ant (as well as junit and maven command line tools) are now part of OSX v10.5 proper.
October 19, 2010
1:01 pm on Tuesday
Thanks! This was quite useful. You may also want to mention ~/.profile as an alternative to bashrc.
November 09, 2010
10:22 am on Tuesday
hi there
just to say that this post was very helpful for me… thank you for share your knowledge with the community. ;-)
January 17, 2011
12:59 pm on Monday
Hello, This is absolutely good. I like the way you constructed your words.
Approvingly done and preserve it up!
January 31, 2011
9:51 pm on Monday
Thank you! This was perfectly helpful.
June 08, 2011
7:39 am on Wednesday
Great! Thanks!
August 01, 2011
12:55 pm on Monday
Thank you very much. Followed it through and it worked like a charm for me. Being new to Mac this helps a lot.
March 29, 2012
1:09 pm on Thursday
Thank you! I just followed this exactly on Mac OS X Lion 10.7.3, and I got to the build failed message:
“Buildfile: build.xml does not exist!
Build failed”
July 04, 2012
3:20 am on Wednesday
Benxamin, This post is very old…
are you sure Lion did not already come with Ant? Try in terminal:
$ant -version
$which ant
I found ant in /usr/bin/ant
Admittedly, on older Mac I used these instructions. But I do not recall installing it again recently.
Also, sometimes package managers (MacPorts or Homebrew) carry easy installers for popular developer tools — like Ant.
Hope this helps!