java_home environment variable is not set ubuntu code example

Example 1: how to set java_home in ubuntu

#Update repo
sudo apt update

# Install java 8 from ubuntu repo
sudo apt install openjdk-8-jdk -y

#Set JAVA_HOME Path
ls /usr/lib/jvm/java-8-openjdk-amd64/
 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
 echo $JAVA_HOME
 
 #Add JAVA bin directory to the PATH variable
 export PATH=$PATH:$JAVA_HOME/bin
 echo $PATH
 java -version

Example 2: ubuntu change default java path

sudo update-alternatives --config java

Example 3: set $JAVA_HOME variable in ubuntu

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Tags:

Java Example