How to Install Java Standard Edition on a CentOS Cloud Server?

04-02-2024 02:43:01

Java is a popular application software platform that is compatible with a wide range of hardware and software environments. There are three versions of Java: Standard Edition (SE), Enterprise Edition (EE), and Micro Edition (ME). This article will focus solely on Java Standard Edition. There are two deployment options for Java Standard Edition: OpenJDK and Oracle Java. These two options have almost identical source code, with only minor differences. In short, OpenJDK is completely open-source, licensed under the GNU General Public License (GPL), whereas Oracle Java includes some proprietary third-party components, including commercial components.

Additionally, Java comes with two types of installation packages: the Java Runtime Environment (JRE) and the Java Development Kit (JDK). The JRE is necessary for running compiled Java applications, while the JDK is required for developing Java applications. Currently, there are three widely used versions of Java Standard Edition: 6, 7, and 8. Therefore, when installing Java, it's important to select the appropriate installation package and version.

It's worth noting that only one version of Java needs to be installed, although Java itself supports installing multiple versions on a single operating system. In a multi-version Java environment, it's necessary to set several common environment variables and also to set a default Java version.

The commands to install OpenJDK 8 are as follows.

  • JRE: sudo yum install -y java-1.8.0-openjdk
  • JDK: sudo yum install -y java-1.8.0-openjdk-devel

The commands to install OpenJDK 7 are as follows.

  • JRE: sudo yum install -y java-1.7.0-openjdk
  • JDK: sudo yum install -y java-1.7.0-openjdk-devel

The commands to install OpenJDK 6 are as follows.

  • JRE: sudo yum install -y java-1.6.0-openjdk
  • JDK: sudo yum install -y java-1.6.0-openjdk-devel

For Oracle Java, the installation process differs from OpenJDK, requiring the download of source code and execution of compile steps, which are relatively more cumbersome, thus its installation is not recommended.

After installation, check the Java version number.

sudo java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

Regardless of the version of Java installed, it is necessary to set environment variables for daily use. In a multi-version Java environment, it's also possible to set the default Java version through environment variables.

sudo vi /etc/profile

To do this, add the following code to the end of the file, replacing "jdk1.8.0_66" with the actual Java version.

export JAVA_HOME=/usr/java/jdk1.8.0_66
export JRE_HOME=/usr/java/jdk1.8.0_66/jre
export PATH=$PATH:/usr/java/jdk1.8.0_66/bin

Finally, execute the source command to activate the changes.

source /etc/profile