Follow these steps to install Java:
- Update the package index:
sudo apt-get update
- Next, install Java. The following command will install the JRE:
sudo apt-get install default-jre
- To set the JAVA_HOME environment variable, first get the Java installation location. Do this by executing the following command:
update-java-alternatives –l
- You should get a similar output:
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
- The path in the preceding output is the JAVA_HOME location. Copy it.
- Open the /etc/environment file for editing:
sudo nano /etc/environment
- Add the following line inside the /etc/environment file, as shown here:
JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64"
- Type Ctrl + X and choose ...