JDK installation under linux

I thought the installation of jdk had been recorded before (but it was not). Now re-record:

Reference blog: https://www.cnblogs.com/Dylansuns/p/6974272.html

1. Check if JDK is installed

java -version
show:
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)
Second, detect the jdk installation package

rpm -qa | grep java
show:

python-javapackages-3.4.1-6.el7_0.noarch
tzdata-java-2015a-1.el7.noarch
javapackages-tools-3.4.1-6.el7_0.noarch
3. Uninstall jdk

Uninstall method I use:

yum remove *openjdk*
Other uninstall methods ( not personally tested )

rpm -e --nodeps tzdata-java-2016g-2.el7.noarch
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
Check the uninstallation:

rpm -qa | grep java
Fourth, install the new JDK

Download JDK on the official website: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Unzip the compressed package

tar -zxvf jdk-8u161-linux-x64.tar.gz

Modify the profile file (directory: /etc/profile) and add the following sections
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

#----------------- Here are the additions ---------------------------- -----
JAVA_HOME=/usr/java/jdk1.8.0_161
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
#-----------------The above is the added part---------------------------- -----

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            be
    esac
}
#The following part is omitted
Execute the profile file
source /etc/profile
View the newly installed JDK
java -version
end of installation










Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325734444&siteId=291194637