187
votes

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?

8
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
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
Can you run "ls -ld /usr/local"? It sounds like you've made a file called "/usr/local". :)Dominic Mitchell
(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

8 Answers

375
votes

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
182
votes

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.

45
votes

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

sudo port install apache-ant
38
votes

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

brew install ant

5
votes

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!

1
votes

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
votes

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
votes

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

$ sudo port install apache-ant

and it will install.