Debian
OpenJDK
Update package information:
apt-get update
Install
apt-get install default-jdk
Or
apt-get install default-jre
Ubuntu
OpenJDK
Then update the package information:
apt-get update
Install
apt-get install default-jre
Or
apt-get install default-jdk
CentOS
OpenJDK
Run the command
yum install java-1.7.0-openjdk
Manage Java
One server can have multiple Java installations at the same time. You can use the update-alternatives command to select the version of Java that will be used by the system by default
sudo update-alternatives --config java
JAVA_HOME variable
Many programs use the JAVA_HOME environment variable to determine where Java is installed. To set this variable, you must first find out exactly where the Java installation is stored
To do this, this command is used:
sudo update-alternatives --config java
Copy the path of the desired version of the program and open /etc/environment in a text editor:
sudo nano /etc/environment
Add the following line to the end of the file (replace the conditional path of the program with the just copied path):
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
Save and close the file. To update the settings, enter:
source /etc/environment
Make sure that the environment variable is set. To do this, type:
echo $JAVA_HOME
The command should return the path you set.