For microservice development I just download and install the Standard Edition (SE) of the JDK. The installer places the JDK into /Library/Java/JavaVirtualMachines. It also adds the Java Control Panel into System Preferences. Now Java is ready to use. Open a terminal and run the following:
It should report the version the JDK just installed.
Next I download Maven. There is no installer. I just download the folder archive. I unzip the folder and place it in /usr/local/. So the end result is /usr/local/apache-maven-3.3.9.
To finish off the installation I setup my dot files. The JDK doesn’t need this but to get Maven working the PATH variable needs to be set.
I setup the ~/.bash_profile file this way so it executes the ~/.bashrc automatically. The .bash_profile executes when a user logs into a machine in the shell but in the case of macOS it is executed every time the Terminal app is opened. I put all configuration in the .bashrc so it is one place and will execute under other circumstances.
I set the prompt to the current working directory. I have experimented with different values for the shell prompt (PS1) however I keep coming back to the brevity of just the path. I set the JAVA_HOME to a recent trick I learned for macOS (/usr/libexec/java_home) which can make it easy to switch between versions of Java. MAVEN_HOME gets set to the expected path. I update PATH to include /usr/local/bin so that anything I download and place there overrides what Apple provides or installs.
You can see my dotfiles repo at https://github.com/jamesdschmidt/dotfiles.
If you have any suggestions or alternative ways to do this add it to the comments below.