200

I tried to install Apache Ant on my Mac and I followed the next steps :

  1. I downloaded apache-ant-1.8.1-bin.tar.gz into my Downloads folder.
  2. I moved the file to /usr/local/ using this commands : sudo sh and mv apache-ant-1.8.1-bin.tar.gz /usr/local/

Now I want to use cd /usr/local/ but it's not working, I get back "No such file or directory".

Then I used cd /usr/ and ls commands and it seems that the local folder is there. If I try to access it I get the same error.

Since I already used sudo su why I can't access it? Any ideas?

4
  • Can you try all of this again, then when it stops working type history Copy paste the commands into the question and we can see where its going wrong. I think you just aren't moving the file into the directory.
    – Steve
    Jul 11, 2010 at 11:24
  • 3
    What is wrong with the version of ant that Mac OS X already has? Install Xcode and you get ant, maven, all the Java development and lots of other useful stuff for development.
    – Cromulent
    Jul 11, 2010 at 11:25
  • Can you run "ls -ld /usr/local"? It sounds like you've made a file called "/usr/local". :) Jul 11, 2010 at 18:46
  • (Mac user) ant --version does not display any version, however, I can see that ant is part of the Android Studio's install of gradle. I do not see any ant on my system related to Xcode. What is the recommendation to either enable using ant in gradle or installing yet-another copy using homebrew.
    – mobibob
    Jul 30, 2019 at 12:13

8 Answers 8

397

Ant is already installed on some older versions of Mac OS X, so you should run ant -version to test if it is installed before attempting to install it.

If it is not already installed, then your best bet is to install Homebrew (brew install ant) or MacPorts (sudo port install apache-ant), and use those tools to install Apache Ant.

Alternatively, though I would highly advise using Homebrew or MacPorts instead, you can install Apache Ant manually. To do so, you would need to:

  1. Decompress the .tar.gz file.
  2. Optionally put it somewhere.
  3. Put the "bin" subdirectory in your path.

The commands that you would need, assuming apache-ant-1.8.1-bin.tar.gz (replace 1.8.1 with the actual version) were still in your Downloads directory, would be the following (explanatory comments included):

cd ~/Downloads # Let's get into your downloads folder.
tar -xvzf apache-ant-1.8.1-bin.tar.gz # Extract the folder
sudo mkdir -p /usr/local # Ensure that /usr/local exists
sudo cp -rf apache-ant-1.8.1-bin /usr/local/apache-ant # Copy it into /usr/local
# Add the new version of Ant to current terminal session
export PATH=/usr/local/apache-ant/bin:"$PATH"
# Add the new version of Ant to future terminal sessions
echo 'export PATH=/usr/local/apache-ant/bin:"$PATH"' >> ~/.profile
# Verify new version of ant
ant -version
7
  • Thank you very much for your help. I didn't know that ant is already installed on my system. I already have Xcode installed, and I needed Ant to setup the environment for GTW and Android development. Thank you. Jul 11, 2010 at 15:10
  • 47
    For the record, there seem to be systems that don't have ant installed; this could have changed since you answered this. I'm running 10.9 and it doesn't have ant anywhere
    – taxilian
    Jul 19, 2013 at 21:39
  • 9
    same here...10.9 doesn't have ant installed by default
    – i_raqz
    Nov 27, 2013 at 11:39
  • 1
    Just a heads up: the last line should be ant -version, with one hyphen
    – Greg Owen
    Jun 9, 2014 at 22:23
  • 1
    On newer versions of OS X, looks like ".profile" should instead be ".bash_profile"
    – Chicowitz
    Mar 30, 2016 at 21:44
183

For MacOS Maveriks (10.9 and perhaps later versions too), Apache Ant does not come bundled with the operating system and so must be installed manually. You can use brew to easily install ant. Simply execute the following command in a terminal window to install brew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

It's a medium sized download which took me 10min to download and install. Just follow the process which involves installing various components. If you already have brew installed, make sure it's up to date by executing:

brew update

Once installed you can simply type:

brew install ant

Ant is now installed and available through the "ant" command in the terminal.

To test the installation, just type "ant -version" into a terminal window. You should get the following output:

Apache Ant(TM) version X.X.X compiled on MONTH DAY YEAR

Source: Error executing command 'ant' on Mac OS X 10.9 Mavericks when building for Android with PhoneGap/Cordova

If you are getting errors installing Brew, try uninstalling first using the command:

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

Thanks to OrangeDog and other users for providing additional information.

3
  • 2
    had an error with permissions on /usr/local so need to run sudo chown -R $USER /usr/local
    – svnm
    Aug 4, 2015 at 13:58
  • That worked but the homebrew installation is a bit weird because although /usr/local/bin/ant is a symbolic link to ../Cellar/ant/1.9.6/bin/ant if you need any customs jars they need to go into ../Cellar/ant/1.9.6/libexec/lib not ../Cellar/ant/1.9.6/lib, and also if you set ANT_HOME to /usr/local/Cellar/ant/1.9.6 it breaks ant so you have to leave it unset Nov 5, 2015 at 11:37
  • 1
    After trying many other things I switched to this answer and it works :). Thank you. Only thing I need to do is, to delete the old version of xCode (ie. 7.3.1 where in current version is 9.0, not sure about what the dependency is but after deleting xCode 7.3.1, everything works like a charm.)
    – iLearner
    Nov 13, 2017 at 5:28
45

If you have MacPorts installed (https://www.macports.org/), do this:

sudo port install apache-ant
1
  • Yep, since Java was removed in 10.9 this seems like the way to go.
    – sehugg
    Nov 9, 2013 at 16:27
40

If you're a homebrew user instead of macports, homebrew has an ant recipe.

brew install ant

0
6

To get Ant running on your Mac in 5 minutes, follow these steps.

Open up your terminal.

Perform these commands in order:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install ant

If you don't have Java installed yet, you will get the following error: "Error: An unsatisfied requirement failed this build." Run this command next: brew cask install java to fix this.

The installation will resume.

Check your version of by running this command:

ant -version

And you're ready to go!

0
1

Use Brew is always good way to install ANT and other needs. To install type below command on terminal.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

after Brew installation , type

brew install ant

This will install Ant on your system. Also you will not need to worry about setting up the path.

Also i have documented on the same - How to Install ANT on Mac OS?

0
0

The only way i could get my ant version updated on the mac from 1.8.2 to 1.9.1 was by following instructions here

http://wiki.eclipse.org/Ant/User_Guide

0

MacPorts will install ant for you in MacOSX 10.9. Just use

$ sudo port install apache-ant

and it will install.

1
  • 8
    How is this different from the already existing answer by Karl von Moor??
    – fishinear
    Aug 11, 2014 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.