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 -versionagain now, it should return details of the installed JDK.
- Next, you'll need to add the
$JAVA_HOMEvariable in your
.bash_profile(if you have a
.bash_profile, you can skip the next step). If you run
echo $JAVA_HOMEand 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 with
- Open your
open -e .bash_profile.
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 (
.bash_profileagain 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.
If you're using the same terminal, go ahead and clear it with
CMD + K. Run
source .bash_profileto refresh it and then run
mvn -versionwill return info on what was just installed.
That's it - happy coding!