Installation and environment configuration of Java under CentOS

Source: Internet
Author: User
Tags prepare

Many articles on the Internet, but I still do not know who needs to see next time, or to recommend to friends who, simply I have to organize out, convenient next time you need to be able to quickly see or link to a friend.
Two mounting methods: decompression, installation and package installation

1. Pre-installation check:
Because of the different services selected when installing the system, sometimes the service system we choose does not pre-install OPENJDK, but it is sometimes preinstalled, so it is best to check the current system for any other JDK versions when installing SUNJDK. "What's the difference between OpenJDK and sunjdk?" See note "

· Check

[Email protected] ~]$ Rpm-qa | grep JDK                     (filter The record information that contains the JDK in the installed package) java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_ 64copy-jdk-configs-3.3-2.el7.noarchjava-1.7.0-openjdk-headless-1.7.0.171-2.6.13.2.el7.x86_ 64java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64

As on the pre-installed package, there is generally no need to keep

[[Email protected] ~]$ java                                    (Java instructions available) Usage:java [-options] class [args ...]           (to execute a class)   Or  Java [-options]-jar jarfile [args ...]           (To execute a jar file)

As shown above is the normal display using Java instructions

[[email protected] ~]$ java-version                            (view Java version) OpenJDK version "1.8.0_161" OPENJDK Runtime Environment (build 1.8.0_ 161-B14) OpenJDK 64-bit Server VM (build 25.161-b14, Mixed mode)

As above is the JDK version currently in use

[[email protected] ~]$ javac                                    (javac instruction not available) Bash:javac:command not found ... Similar command is: ' Java '

If the instructions on using Javac are unsuccessful

· Uninstall the unwanted JDK version, if it is not negligible (note that this is the root user, before all Mario users)

[[email protected] ~]# Yum remove *openjdk*                    (Uninstall package containing openjdk) [[email protected] ~]# rpm-e copy-jdk-configs                 (Uninstall Copy-jdk-configs package)

As above are two kinds of unloading, you can use Yum one-time match, but pay attention not to the need to unload the package, or use RPM-E to uninstall each, but note the dependency of the package

· Uninstall complete monitoring results are as follows

[Email protected] ~]$ Rpm-aq |  grep jdk[[email protected] ~]$ Java-bash:/usr/bin/java:no such file or Directory[[email protected] ~]$ Javacbash:javac: Command not found ...

If the above is uninstalled, the monitoring results display

2. Installation
2.1 Package Installation:
· Prepare jdk-8u171-linux-x64.rpm,http://www.oracle.com/technetwork/java/javase/downloads/index.html (You can select the desired version)
· The installation process is as follows

[Email protected] downloads]# rpm-i jdk-8u171-linux-x64.rpm

· Post-installation detection

[Email protected] java]# pwd/usr/java[[email protected] java]# lltotal 0lrwxrwxrwx. 1 root root  16:00 Default-/usr/java/latestdrwxr-xr-x. 9 root root 268 June 16:00 jdk1.8.0_171-amd64l Rwxrwxrwx. 1 root root  16:00 latest-/USR/JAVA/JDK1.8.0_171-AMD64

There is no need to configure environment variables after installation, Java Directives and Javac directives are available, and their associated installation information is under the/usr/java path
Note: In order to facilitate the configuration of Java-dependent applications, we can also configure the environment variables, see the/etc/profile details in the 2.2 decompression installation
2.2 Unzip the installation:
· Prepare jdk-8u171-linux-x64.tar.gzhttp://www.oracle.com/technetwork/java/javase/downloads/index.html (You can select the desired version)
· Start installation
Create the installation path

        [Email protected] ~]# Mkdir/usr/java

Unzip the compressed file to the installation path

        [Email protected] ~]# tar-xzf/home/mario/downloads/jdk-8u171-linux-x64.tar.gz-c/usr/java/

Configuring Environment variables

        [Email protected] ~]# Vim/etc/profile

Add content as follows

        Export java_home=/usr/java/jdk1.8.0_171 export        jre_home=${java_home}/jre        export classpath=.:${java_home}/ Lib:${jre_home}/lib        export Path=${java_home}/bin: $PATH

Reload file

        [Email protected] ~]# Source/etc/profile

· Detect Java instructions after installation, JAVAC instructions can be used

"Note" See 53081205 (Thanks here)
(1) Differences in licensing agreements
(2) OpenJDK does not include deployment (deployment) function
(3) OpenJDK source code is not complete
(4) Some source code is replaced with open source code
(5) OpenJDK contains only the most streamlined JDK
(6) Cannot use Java trademark

Installation and environment configuration of Java under CentOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.