Enabling Java in macOS
If you want to use a Java-based app on your Mac, you would think the path forward is obvious: Download and install Java, then run your app.
Well…no. Even now in late 2020, it’s not that easy. Oracle’s Java installer inexplicably doesn’t add the path to Java or set the JAVA_HOME environment variable, so you’ll get an error that you need to install the latest JDK, even though you just did.
So how do you fix it? Googling will yield frustration. There are lots of sites telling you how to fix it, but few of the answers actually work.
The irony is that the fix only takes 2 minutes and is easy. The problem is that it’s hidden at the bottom of the twelfth Stackoverflow discussion you’ll find. Here it is right at the top of this post so you can do it yourself quickly.
Things to know:
- You need to edit your
~/.bash_profile
file. - This file does not exist by default, even though most posts claim it does.
- You need to know the path to java home, and it does not include the version number.
Ok, let’s get down to it. Here are your steps:
- Open Terminal.
- Enter this command:
vi ~/.bash_profile
- Press the “i” key to enable insertion mode.
- Cut & paste in this line:
export JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
- Press the esc key to leave insertion mode.
- Press Z Z to save the file and leave vi.
- Enter this command:
source .bash_profile
- Enter this command to ensure the changes took effect:
echo $JAVA_HOME
Your Java apps should now function. Further, because you didn’t change your path and/or use a specific Java version, you should be able to install Java updates and not lose functionality. Also, this should work across all versions of macOS.
Enjoy!