Install JDK 1.8 In CentOS 7

Source: Internet
Author: User

Install JDK 1.8 In CentOS 7

Currently, jdk1.6 and 1.7 are used by default in CentOS 7. If we need a later version of 1.8, we need some additional means.

First, we need to download the latest jdk. oraclew.rpmpackage and the tar.gz package from the next version of this page. To save trouble, download an rpm package.

After the download is complete, you can use the rpm command to install it, but lazy people prefer to use yum.

# Yum localinstall jdk-8u20-linux-x64.rpm-y
...
Resolving Dependencies
--> Running transaction check
---> Package jdk1.8.0 _ 20. x86_64 2000. 8.0 _ 20-fcs will be installed
--> Finished Dependency Resolution
...
Installed:
Jdk1.8.0 _ 20. x86_64 2000. 8.0 _ 20-fcs
 
Complete!

After installation, you can delete the rpm package to save space.

This jdk is actually configured with an environment under the/usr/java directory. Check this directory. We can see that there are multiple jdk1.8.0 _ 20 files in the directory, and the soft links are linked to the default and last directories.

$ Ls-al/usr/java
Total 12
Drwxr-xr-x. 3 root 4096 Oct 13.
Drwxr-xr-x. 15 root 4096 Jul 31 ..
Lrwxrwxrwx. 1 root 16 Oct 13 default->/usr/java/latest
Drwxr-xr-x. 9 root 4096 Oct 13 jdk1.8.0 _ 20
Lrwxrwxrwx. 1 root 21 Oct 13 latest->/usr/java/jdk1.8.0 _ 20

However, it is not actually used so far. We need to use the alternative tool to manage it.

For soft links, if we direct the configuration content to/usr/java/default/bin/xxx and install jdk 1.9 or 2.0 in the future, you just need to directly modify the soft link, instead of having to do it again. therefore, I will use/usr/java/default/as the new java home.

However, if you are not planning to do this by accident, but want to use JDK 1.8.0 _ 20 instead of changing it, replace default with JDK 1.8.0 _ 20. This is the case in similar cases. Please note that.

First, check the current alternative environment.

# Alternatives -- config java
 
There is 1 program that provides 'java '.
 
Selection Command
-----------------------------------------------
* + 1/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre/bin/java
 
Enter to keep the current selection [+], or type selection number: ^ C

We have noticed that alternatives already has a java, and our goal is to add one without damaging the original environment. 8. of course, after everything is done, you can also try to delete the rpm package installed on your own.

We first add java to alternative
 
# Alternatives -- install/usr/bin/java/usr/java/default/bin/java 2

Several parameters are easy to understand, that is, the executable file/usr/java/default/bin/java Soft link/usr/bin/java, the configuration name is java, the last parameter 2 is because we have seen that we already have a java, so index is set to 2.

Continue to configure

# Alternatives -- config java
 
There are 2 programs which provide 'java '.
 
Selection Command
-----------------------------------------------
* + 1/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre/bin/java
2/usr/java/default/bin/java
 
Enter to keep the current selection [+], or type selection number: 2
 

We found that an alternative exists, pointing to the newly installed/usr/java/defalut/bin/java. Select this command.

Check again:

# Alternatives -- config java
 
There are 2 programs which provide 'java '.
 
Selection Command
-----------------------------------------------
* 1/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre/bin/java
+ 2/usr/java/default/bin/java
 
Enter to keep the current selection [+], or type selection number: 2

We found that the number + has been moved below.

Similarly, we can configure the remaining

# Alternatives -- install/usr/bin/jar/usr/java/default/bin/jar 2
# Alternatives -- install/usr/bin/javac/usr/java/default/bin/javac 2
# Alternatives -- set jar/usr/java/default/bin/jar
# Alternatives -- set javac/usr/java/default/bin/javac

This is done.

Finally, we can verify that:

$ Java-version
Java version "1.8.0 _ 20"
Java (TM) SE Runtime Environment (build 1.8.0 _ 20-b26)
Java HotSpot (TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
$ Javac-version
Javac 1.8.0 _ 20

Finally, we may need to configure environment variables.
Environment variables can be configured under normal users.
Can be written directly
 
$ Export JAVA_HOME =/usr/java/default

And other blabla.

However, we can also write it into the configuration file. Depends on the use of shell. If bash is used, you can ~ /. Bashrc or ~ /. Add the following content to bash_profile:

Export JAVA_HOME =/usr/java/default
Export JRE_HOME =/usr/java/default/jre
Export PATH = $ PATH: $ JAVA_HOME/bin: $ JRE_HOME/bin

 

Install JDK 7 In Ubuntu (with Clojure download)

Install JDK 12.04 in Ubuntu

CentOS6.3 install JDK and environment Configuration

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.