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:
- Open a new terminal and run
java -version
. If you don't have a JDK installed, you can download it here. - You can check the installed Java path by going to your Mac's
Settings > Java > Java (within the Java Control Panel) > Path
. - In your terminal, if you run
java -version
again now, it should return details of the installed JDK. - 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 runecho $JAVA_HOME
and it returns blank, it means you haven't set the variable yet. - If you don't have a
.bash_profile
, go ahead and create one withtouch .bash_profile
. - Open your
.bash_profile
by runningopen -e .bash_profile
. - Add
export JAVA_HOME=$(/usr/libexec/java_home)
to the file and save it.
How to set up Maven:
- Download Maven here. This tutorial follows downloading the binary zip archive file.
- Once it's downloaded, move it into your Applications folder and unzip it (
unzip apache-maven-3.6.3-bin.zip
). 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
If you're using the same terminal, go ahead and clear it with
CMD + K
. Runsource .bash_profile
to refresh it and then runmvn -version
.If successful,
mvn -version
will return info on what was just installed.
That's it - happy coding!
Top comments (1)
Hi Jeannie, thank you very much for the tutorial. But I still have issues when verifying the JAVA_HOME using echo command. After setting above steps in bash_profile and running echo command I get JAVA_HOME only but noth the complete path. Could you please help me in this regard? Thanks.