Install OpenJDK and Set JAVA_HOME Path in Ubuntu
Mainly Java-based programs need to run the Java Runtime Environment (JRE) smoothly regardless of the operating system. Now we can discuss how to set JAVA_HOME in Ubuntu.
1. Install OpenJDK on Ubuntu
Note: make sure that you have updated an advanced package tool (APT) before you start the install OpenJDK.
If you want to update APT, you can use the following syntax.
sudo apt-get update
Press Ctrl + Alt + T to open the terminal and enter the following command to install OpenJDK.
sudo apt install openjdk-8-jdk
Wait for the system to finish the installation then move to the second step.
2. Set JAVA_HOME Path
Now your installation is completed. All you have to do now set the “JAVA_HOME” and “PATH” environment variables.
Firstly make sure that your environment variable installations point to a valid installation.
normally, the ubuntu path is usr/lib/jvm/java-8-openjdk-amd64/
then you can execute the following commands.
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
When your JAVA_HOME path has been successfully saved, execute the following commands to check.
echo $JAVA_HOME
3. Add JAVA bin directory to the PATH variable
Like added JAVA_HOME path, now we will update the PATH variable.
export PATH=$PATH:$JAVA_HOME/bin
Like check the JAVA_HOME path, You can check the PATH variable by entering the following command.
echo $PATH
4. Test JAVA
You have successfully installed OpenJDK on your computer. So executed the following command you can verify your installation.
java -version
Through this simple tutorial, you have now configured the JAVA_HOME variable in your operating system.