Check the java version with the command java -version if it successfully installed then you can see the version else you will see the below image.
Java –version
If you get result similar to the below image you do not have Java installed. The list shows you which packages in your system have Java available and you have to install it.
If you do not have the correct version of Java, please download Java 11 from here. ( Note: Oracle login might be required, if you do not have you can register for free and download)
Installation Steps:
- Check for Java Installation
- Login to Ubuntu
- Check if Java is not already installed or not using command
- To install OpenJDK 8, execute the following command:
- This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), execute the following command:
- To set the JAVA_HOME environment variable, which is needed for some programs, first find out the path of your Java installation:
- /usr/lib/jvm/java-8-oracle
- /usr/lib/jvm/java-6-openjdk-amd64
- /usr/lib/jvm/java-7-oracle
- Copy the path from your preferred installation and then edit the file /etc/environment:
- In this file, add the following line (replacing YOUR_PATH by the just copied path):
- Test it by executing:
java -version
Installing OpenJDK 8:
sudo apt-get install openjdk-8-jre
sudo apt-get install openjdk-8-jdk
sudo update-alternatives –config java
It returns something like:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status:
* 0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1062 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 manual mode
Press enter to keep the current choice[*], or type selection number:
The path of the installation is for each:
sudo nano /etc/environment
JAVA_HOME=”YOUR_PATH”
That should be enough to set the environment variable. Now reload this file:
source /etc/environment
echo $JAVA_HOME
If it returns the just set path, the environment variable has been set successfully. If it doesn’t, please make sure you followed all steps correctly.