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:
- Login to Ubuntu
- Check whether Java is already installed by running the following command:
java -version
If java 11 is not present then we have to install Java 11. Follow below steps for installation.
- To install the 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:
- Test it by executing:
Installing OpenJDK 11:
sudo apt-get install openjdk-11-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-11-openjdk-amd64/bin/java 1111 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1112 manual mode Press <enter> to keep the current choice[*], or type selection number:
In the example above, the path for Java 11 is:
/usr/lib/jvm/java-11-openjdk-amd64
Set the JAVA_HOME environment variable:
Add the following line to your ~/.bashrc
, ~/.zshrc
, or ~/.profile
file, depending on your shell:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH
Apply the changes:
source ~/.bashrc # or the appropriate config file
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.