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: