loading...
Cover image for How to Install Java JDK and Maven on Mac OS

How to Install Java JDK and Maven on Mac OS

jeannienguyen profile image Jeannie Nguyen ・2 min read

I've needed to set up Java and Maven enough times that I figured I should write about it so that it's an easier setup for at least one other person.

You can skip the first half if you already have Java JDK installed.

How to set up Java JDK:

  1. Open a new terminal and run java -version. If you don't have a JDK installed, you can download it here.
  2. You can check the installed Java path by going to your Mac's Settings > Java > Java (within the Java Control Panel) > Path.
  3. In your terminal, if you run java -version again now, it should return details of the installed JDK.
  4. Next, you'll need to add the $JAVA_HOME variable in your .bash_profile (if you have a .bash_profile, you can skip the next step). If you run echo $JAVA_HOME and it returns blank, it means you haven't set the variable yet.
  5. If you don't have a .bash_profile, go ahead and create one with touch .bash_profile.
  6. Open your .bash_profile by running open -e .bash_profile.
  7. Add export JAVA_HOME=$(/usr/libexec/java_home) to the file and save it.

How to set up Maven:

  1. Download Maven here. This tutorial follows downloading the binary zip archive file.
  2. Once it's downloaded, move it into your Applications folder and unzip it (unzip apache-maven-3.6.3-bin.zip).
  3. Open your .bash_profile again and add these two variables. Version number will vary based on when you're reading this. The latest version as of 08/26/20 is 3.6.3.

    export M2_HOME=/Applications/apache-maven-3.6.3
    export PATH=$PATH:$M2_HOME/bin

  4. If you're using the same terminal, go ahead and clear it with CMD + K. Run source .bash_profile to refresh it and then run mvn -version.

  5. If successful, mvn -version will return info on what was just installed.

That's it - happy coding!

Posted on by:

jeannienguyen profile

Jeannie Nguyen

@jeannienguyen

Writing about everything I learn on the web and sharing it so you can learn with me.

Discussion

pic
Editor guide