Three methods for installing JDK under CentOS: centosjdk

Source: Internet
Author: User

Three methods for installing JDK under CentOS: centosjdk

Because of the differences between Linux development vendors, the operating details of Linux versions vary with development vendors. Today, let's talk about how to install JDK in CentOS:

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

Method 4: Install JDK with apt-get on Ubuntu

1. Check which jdk versions are available in the apt library.

root@Itble:~# apt-cache search java|grep jdkdefault-jdk - Standard Java or Java compatible Development Kitdefault-jdk-doc - Standard Java or Java compatible Development Kit (documentation)gcj-4.6-jdk - gcj and classpath development tools for Java(TM)gcj-jdk - gcj and classpath development tools for Java(TM)openjdk-6-dbg - Java runtime based on OpenJDK (debugging symbols)openjdk-6-demo - Java runtime based on OpenJDK (demos and examples)openjdk-6-doc - OpenJDK Development Kit (JDK) documentationopenjdk-6-jdk - OpenJDK Development Kit (JDK)openjdk-6-jre-lib - OpenJDK Java runtime (architecture independent libraries)openjdk-6-source - OpenJDK Development Kit (JDK) source filesopenjdk-7-dbg - Java runtime based on OpenJDK (debugging symbols)openjdk-7-demo - Java runtime based on OpenJDK (demos and examples)openjdk-7-doc - OpenJDK Development Kit (JDK) documentationopenjdk-7-jdk - OpenJDK Development Kit (JDK)openjdk-7-source - OpenJDK Development Kit (JDK) source filesuwsgi-plugin-jvm-openjdk-6 - Java plugin for uWSGI (OpenJDK 6)uwsgi-plugin-jwsgi-openjdk-6 - JWSGI plugin for uWSGI (OpenJDK 6)openjdk-6-jre - OpenJDK Java runtime, using Hotspot JITopenjdk-6-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)openjdk-7-jre - OpenJDK Java runtime, using Hotspot JITopenjdk-7-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)openjdk-7-jre-lib - OpenJDK Java runtime (architecture independent libraries)

2. Select a version for installation.

root@Itble:~# apt-get install openjdk-7-jdk

3. Set Environment Variables

root@Itble:~# vi /etc/profile

Add the following content to the opened profile file:

#set java environmentJAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64JRE_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@Itble:~# source /etc/profile

4. Verification (same method)

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.