If you install JAVA through your distro's default package manager(for example I use Ubuntu so I install Java(the OpenJDK version of Java) through APT [so the command to install OpenJDK's Java17 for example is sudo apt install openjdk-17-jdk
]). Regardless of the version you install via APT, Java will be installed in the /usr/lib/jvm/{java-version-distribution-architecture}
path. So, the easiest way to set the JAVA_HOME variable is to edit your .bashrc
file and add this inside it using your text editor:
JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export JAVA_HOME
PATH=$PATH:JAVA_HOME/bin
export PATH
Save and close the file after adding this information inside it. Then run the command source .bashrc
(to stamp you changes) and the JAVA_HOME will be permanently set. Also note that the .bashrc
file is located in the ~/.bashrc
(your home). You can confirm the JAVA_HOME variable by using the command echo $JAVA_HOME
on the terminal and it should show you the path you just set. I hope this helps