Thursday 9 May 2019

How to install Java and set JAVA_HOME Path in Ubuntu [Solved]

$ sudo apt-get update


$ sudo apt-get upgrade

Install OpenJDK 8 on Ubuntu

Press Ctrl + Alt + T to open the terminal and enter the following command mentioned in the box.
$ sudo apt install openjdk-8-jdk


It is also possible to install only the JRE, which you can do by executing sudo apt install openjdk-8-jre.

Set JAVA_HOME Path

All you have to do now is to set the “JAVA_HOME” and “PATH” environment variables and then you are done. Enter the following commands to set your environment variables.

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

To check whether your JAVA_HOME path has been successfully saved, enter the following command to check.

$ echo $JAVA_HOME

Add JAVA bin directory to the PATH variable

Like we have added JAVA_HOME path, we will now update the PATH variable as well. To do that, enter the following command on the terminal.
$ export PATH=$PATH:$JAVA_HOME/bin

This will append the java bin directory to the existing PATH variable. You can also check the PATH variable by entering the following command
$ echo $PATH

Test JAVA setup

$ java -version

No comments:

Post a Comment