This post describes how to configure the JAVA_HOME environment variable required by many enterprise tools, frameworks, and CMSes. For instance, Liferay, Tomcat, etc. will use this variable to work properly.
Step 1. Be sure you don’t have the JAVA_HOME already set
Run this command:
1 |
echo $JAVA_HOME |
If the output is empty, then we don’t have the variable correctly set.
Step 2. Find the Java Development Kit directory
If you don’t know where the Java Development Kit (JDK) was installed, just run:
1 |
sudo find / -name javac |
The output may be similar to this:
1 2 3 4 5 |
/usr/bin/javac /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin/javac /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/javac find: /private/var/db/ConfigurationProfiles/Store: Operation not permitted find: /private/var/folders/y5/abbasdf/0/SafariFamily: Operation not permitted |
Notice the second line, that is our JDK installation directory, so the directory we need to use is this one: /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/
Step 3. Add the JAVA_HOME to the Bash configuration file
Let’s open the file (if don’t exist, just create it):
1 |
nano ~/.bash_profile |
Add the JAVA_HOME variable at the end of ~/.bash_profile
1 |
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/" |
Save the file ~/.bash_profile (in nano just press Control + O followed by Control + X to close the file). Finally, let’s review or configuration by typing:
1 |
echo $JAVA_HOME |
This command should now print the correct JAVA_HOME:
1 |
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/ |
If you don’t see your environment variable, please close all your terminal windows and re-start them so you have a “fresh” start.
Sweet, isn’t it?
See you next time.
Alex Arriaga