cat <<'EOF' | sudo tee /etc/profile.d/java_home_env.sh >/dev/null
export JAVA_HOME=$(update-alternatives --query java | grep Value | cut -d" " -f2 | sed 's!\(\/.*\)jre\(.*\)!\1!g')
export JDK_HOME=${JAVA_HOME}
export JRE_HOME=${JDK_HOME}/jre/
EOF
因为你的shell在默认情况下可能没有被设置为交互式的,你可能也想这样做:
2.b < / p >
cat <<'EOF' | sudo tee -a /etc/bash.bashrc >/dev/null
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
EOF
#1. set a java_bin variable to the directory containing the actual Java executables.
java_bin=$(readlink -e `which java` | xargs -0 dirname)
#2. append "$java_bin" to the PATH environment variable
export PATH=$PATH:"$java_bin"
#3. assign the directory of the current Java installation to the JAVA_HOME environment variable.
export JAVA_HOME=$(dirname "$java_bin")