Three methods for installing JDK under CentOS: centosjdk

Source: Internet
Author: User

Three methods for installing JDK under CentOS: centosjdk

Method 1: manually decompress the JDK compressed package and set the environment variable

1. Create a java directory under the/usr/directory

[root@localhost ~]# mkdir/usr/java[root@localhost ~]# cd /usr/java

 

2. Download jdk and decompress it.

[root@localhost java]# curl -O http://download.Oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz [root@localhost java]# tar -zxvf jdk-7u79-linux-x64.tar.gz

 

3. Set Environment Variables

[root@localhost java]# vi /etc/profile

 

Add the following content to profile:

#set java environmentJAVA_HOME=/usr/java/jdk1.7.0_79JRE_HOME=/usr/java/jdk1.7.0_79/jreCLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/libPATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/binexport JAVA_HOME JRE_HOME CLASS_PATH PATH

 

Make the modification take effect:

[root@localhost java]# source /etc/profile

 

4. Verify JDK Validity

[root@localhost java]# java -versionjava version "1.7.0_79"Java(TM) SE Runtime Environment (build 1.7.0_79-b15)Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

 

Method 2: Install JDK with yum

1. Check which jdk versions are available in the yum Library (only openjdk is found currently)

[root@localhost ~]# yum search java|grep jdkldapjdk-javadoc.x86_64 : Javadoc for ldapjdkjava-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environmentjava-1.6.0-openjdk-demo.x86_64 : OpenJDK Demosjava-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environmentjava-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentationjava-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundlejava-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environmentjava-1.7.0-openjdk-demo.x86_64 : OpenJDK Demosjava-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environmentjava-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentationjava-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundlejava-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environmentjava-1.8.0-openjdk-demo.x86_64 : OpenJDK Demosjava-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environmentjava-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environmentjava-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentationjava-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundleldapjdk.x86_64 : The Mozilla LDAP Java SDK

 

2. Select a version for installation.

// Select 1.7 for Installation

[root@localhost ~]# yum install java-1.7.0-openjdk


// After the installation is complete, the default installation directory is in:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64

3. Set Environment Variables

[root@localhost ~]# vi /etc/profile

Add the following content to the profile file:

#set java environmentJAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64JRE_HOME=$JAVA_HOME/jreCLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/libPATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/binexport JAVA_HOME JRE_HOME CLASS_PATH PATH

Make the modification take effect

[root@localhost java]# source /etc/profile

4. Verification (same method)

Method 3: Install JDK with rpm

1. Download the rpm Installation File

[root@localhost ~]$ curl -O http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm

2. Run the rpm command to install

[root@localhost  ~]# rpm -ivh jdk-7u79-linux-x64.rpm

3. Set Environment Variables

[root@localhost java]# vi /etc/profile

Add the following content to the opened profile file:

#set java environmentJAVA_HOME=/usr/java/jdk1.7.0_79JRE_HOME=/usr/java/jdk1.7.0_79/jreCLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/libPATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/binexport JAVA_HOME JRE_HOME CLASS_PATH PATH

Make the modification take effect

[root@localhost java]# source /etc/profile

4. Verification (same method)

Note: similar to yum installation, java commands can be run without setting environment variables. By default, the jdk is installed in/usr/java/jdk1.7.0 _ 79 by rpm, and then linked to/usr/bin through a layer-3 link. The specific link is as follows:

[root@localhost ~]# cd /bin[root@localhost bin]# ll|grep javalrwxrwxrwx. 1 root root    25 Mar 28 11:24 jar ->/usr/java/default/bin/jarlrwxrwxrwx. 1 root root    26 Mar 28 11:24 java -> /usr/java/default/bin/javalrwxrwxrwx. 1 root root    27 Mar 28 11:24 javac ->/usr/java/default/bin/javaclrwxrwxrwx. 1 root root    29 Mar 28 11:24 javadoc ->/usr/java/default/bin/javadoclrwxrwxrwx. 1 root root    28 Mar 28 11:24 javaws ->/usr/java/default/bin/javawslrwxrwxrwx. 1 root root    30 Mar 28 11:24 jcontrol ->/usr/java/default/bin/jcontrol[root@localhost bin]# cd /usr/java/[root@localhost java]# lltotal 4lrwxrwxrwx. 1 root root  16 Mar 28 11:24 default-> /usr/java/latestdrwxr-xr-x. 8 root root 4096 Mar 28 11:24 jdk1.7.0_79lrwxrwxrwx. 1 root root  21 Mar 28 11:24 latest -> /usr/java/jdk1.7.0_79

 

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.