Describes how to set JAVA_HOME on Ubuntu.
--java is assumed to go through alternatives. --/ usr / bin / java-> / etc / alternatives / java-> (actual java location) --PATH is in / usr / bin, so it doesn't correspond in particular. --When switching between multiple javas, make it possible to handle it by executing the source command. --See here for how to switch. "Install and switch between multiple Javas on Ubuntu"
--The shell under /etc/profile.d is executed at login.
sudo vi /etc/profile.d/java_home.sh
--The JDK home directory is determined from the absolute path of the java command.
--There are cases of $ {JAVA_HOME} / bin / java
and $ {JAVA_HOME} / jre / bin / java
, so both are supported. (There may be other cases ...)
/etc/profile.d/java_home.sh
export JAVA_HOME=`echo $(dirname $(readlink $(readlink $(which java)))) | sed -e 's/\/bin$//g' | sed -e 's/\/jre$//g'`
source /etc/profile.d/java_home.sh
echo $JAVA_HOME
Recommended Posts