How to install Java on CentOS


Step 1: download https://www.java.com/en/download/manual.jsp

For CentOS 32bits, use Linux RPM
For CentOS 64bits, use Linux x64 RPM

mkdir /usr/java
cd /usr/java
wget http://javadl.oracle.com/webapps/download/AutoDL?BundleId=230531_2f38c3b165be4555a1fa6e98c45e0808 -O jre-8u161-linux-x64.rpm

Result:

[root@tutorialspots ~]# mkdir /usr/java
[root@nguyen-1 ~]# cd /usr/java
[root@nguyen-1 java]# wget http://javadl.oracle.com/webapps/download/AutoDL?Bund
leId=230531_2f38c3b165be4555a1fa6e98c45e0808 -O jre-8u161-linux-x64.rpm
--2018-02-10 19:25:50--  http://javadl.oracle.com/webapps/download/AutoDL?Bundle
Id=230531_2f38c3b165be4555a1fa6e98c45e0808
Resolving javadl.oracle.com (javadl.oracle.com)... 137.254.120.23
Connecting to javadl.oracle.com (javadl.oracle.com)|137.254.120.23|:80... connec
ted.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://sdlc-esd.oracle.com/ESD6/JSCDL/jdk/8u161-b12/2f38c3b165be4555a1
fa6e98c45e0808/jre-8u161-linux-x64.rpm?GroupName=JSC&FilePath=/ESD6/JSCDL/jdk/8u
161-b12/2f38c3b165be4555a1fa6e98c45e0808/jre-8u161-linux-x64.rpm&BHost=javadl.su
n.com&File=jre-8u161-linux-x64.rpm&AuthParam=1518291951_e3d3d15ac294626fc62299b7
9dadbf66&ext=.rpm [following]
--2018-02-10 19:25:51--  http://sdlc-esd.oracle.com/ESD6/JSCDL/jdk/8u161-b12/2f3
8c3b165be4555a1fa6e98c45e0808/jre-8u161-linux-x64.rpm?GroupName=JSC&FilePath=/ES
D6/JSCDL/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jre-8u161-linux-x64.rpm&
BHost=javadl.sun.com&File=jre-8u161-linux-x64.rpm&AuthParam=1518291951_e3d3d15ac
294626fc62299b79dadbf66&ext=.rpm
Resolving sdlc-esd.oracle.com (sdlc-esd.oracle.com)... 88.221.144.80, 88.221.144
.40
Connecting to sdlc-esd.oracle.com (sdlc-esd.oracle.com)|88.221.144.80|:80... con
nected.
HTTP request sent, awaiting response... 200 OK
Length: 63333908 (60M) [application/x-sdlc]
Saving to: `jre-8u161-linux-x64.rpm'

100%[======================================>] 63,333,908  10.2MB/s   in 6.7s

2018-02-10 19:25:58 (9.06 MB/s) - `jre-8u161-linux-x64.rpm' saved [63333908/6333
3908]

Step 2: install

rpm -ivh jre-8u161-linux-x64.rpm

Result:

[root@tutorialspots java]# rpm -ivh jre-8u161-linux-x64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:jre1.8-1.8.0_161-fcs             ################################# [100%]
Unpacking JAR files...
        plugin.jar...
        javaws.jar...
        deploy.jar...
        rt.jar...
        jsse.jar...
        charsets.jar...
        localedata.jar...

You should delete RPM file after the installation:

rm -f jre-8u161-linux-x64.rpm

Step 3: create file /etc/profile.d/java.sh with these lines:

export JAVA_HOME=/usr/java/jre1.8.0_161
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

By using this command:

vi /etc/profile.d/java.sh

Step 4:

export JAVA_HOME=/usr/java/jre1.8.0_161
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

Check:

[root@tutorialspots ~]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

No comments yet.

Leave a Reply