When I started researching about Maven (What is it? Why do I need it? What does it do?) I came across a number of webpages that said that Maven came pre-installed on older version Macs. I have Mavericks on my iMac so I wasnt included in the group that came pre-installed with Maven. There are a set of instructions on the Apache Maven download page (http://maven.apache.org/download.cgi) and a useful YouTube video following these instructions (from Evil Tester Videos, displayed below after the jump.).
Essentially the commands to enter are as follows:
The only problem is these instructions create the environment variables needed for the current session only, they dont tell you how to make these changes permanent. If you reboot or even opena new Terminal window these changes will be lost. These changes must be written to a profile file. There a number of ways to name your profile file and these inclde “.profile”, “.bash-profile” and “.bashrc”. The files that begin with a dot are hidden system files. On a number of webapges the instructions for this step were along the lines of “add these to your .profile” etc. with no indication of how to add the commands to the secret hidden system file. You cant open it with apps like Sublime Text as it cant see the file. (it is hidden after all). A few more sites recommended using vi or emacs. I haven’t used vi or emacs in over 15 years and I wasnt too fond of them then, I certainly wasnt going to reacquaint myself with their unintuitive interfaces if I could help it.
Finally I found the simple answer:
Type that into the command line (from your home directory) and it will open the .profile file in your default application, which in my case is TextEditor. I added the above commands to the .profile file and saved it.
But Maven still wasn’t working. the JAVA_HOME variable wasn’t correct. I searched for and found the solution here. I updated the .profile with this and finally, Maven was working! Here are the fixed commands to add to your .profile:
I found this useful answer on StackExchange on how to install Apache Ant on a Mac. Earlier versions of OSX came with Ant preinstalled but not so on my installation of Mavericks. Before we do anything we need to download the Ant files from http://ant.apache.org/. The code snippet below assumes that you download the .tar.gz version, but you can work around it if you have downloaded one of the other versions and know how to extract the archive. Copy and paste the commands below into your terminal session (I did them one by one. Also the lines beginning with a # are comments).
# Let’s get into your downloads folder.
# Extract the folder (If you have already extracted the downloaded archive, skip this step) /
tar -xvzf apache-ant-1.8.1-bin.tar.gz
# Ensure that /usr/local exists
sudo mkdir -p /usr/local
# Copy it into /usr/local
sudo cp -rf apache-ant-1.8.1-bin /usr/local/apache-ant
# Add the new version of Ant to current terminal session
# Add the new version of Ant to future terminal sessions
echo ‘export PATH=/usr/local/apache-ant/bin:”$PATH”‘ >> ~/.profile
# Demonstrate new version of ant
The last line is just to verify that you have successfully installed Apache Ant. And that’s it, you have successfully installed Apache Ant on your Mac.