Sunday, 20 May 2018

CARA INSTALL JAVA CENTOS


There are also two different implementations of Java, OpenJDK and Oracle Java with almost no differences between them except that Oracle Java has a few additional commercial features.

Install OpenJDK
OpenJDK, the open source implementation of the Java Platform is the default Java development and runtime in CentOS 7.

The installation is simple and straightforward.



Install OpenJDK 8 JRE
sudo yum install java-1.8.0-openjdk
Copy
Install OpenJDK 8 JDK
sudo yum install java-1.8.0-openjdk-devel
Copy
Install OpenJDK 7 JRE
sudo yum install java-1.7.0-openjdk
Copy
Install OpenJDK 7 JDK
sudo yum install java-1.7.0-openjdk-devel
Copy
Advertisement

Install Oracle Java 9 JRE
curl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/9.0.4+11/c2514751926b4512b076cc82f959763f/jre-9.0.4_linux-x64_bin.rpm
sudo yum localinstall jre-9.0.4_linux-x64_bin.rpm
Copy
Install Oracle Java 9 JDK
curl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/9.0.4+11/c2514751926b4512b076cc82f959763f/jdk-9.0.4_linux-x64_bin.rpm
sudo yum localinstall jdk-9.0.4_linux-x64_bin.rpm
Copy
Install Oracle Java 8 JRE
curl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/jre-8u162-linux-x64.rpm
sudo yum localinstall jre-8u162-linux-x64.rpm
Copy
Install Oracle Java 8 JDK
curl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/jdk-8u162-linux-x64.rpm
sudo yum localinstall jdk-8u162-linux-x64.rpm
Copy
Set the default version
We can check the version of our default Java, with:

java -version
Copy
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
Copy
If we have multiple Java versions installed on the server we can change the default version using the alternatives system:

sudo alternatives --config java
Copy
The output should look similar to the following:

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/java/jdk1.8.0_162/jre/bin/java
   2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/bin/java)
   3           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171-2.6.13.0.el7_4.x86_64/jre/bin/java)
*+ 4           /usr/java/jdk-9.0.4/bin/java

Enter to keep the current selection[+], or type selection number:
Copy
Just enter the number when prompted and hit Enter.

Uninstall Java
If for any reason you want to uninstall the Java package, you can unistall it as any other package installed with yum. For example if you want to uninstall the java-1.8.0-openjdk-devel package simply run:

sudo yum remove java-1.8.0-openjdk-devel
Copy
If you have any questions feel free to leave a comment.

No comments:

Post a Comment