Method One: Manual decompression JDK , and then set the environment variable
1. Create a java directory under the/usr/directory
[Email protected] ~]# Mkdir/usr/java
[Email protected] ~]# Cd/usr/java
2. Download, then unzip
[Email protected] java]# Curl-o http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz
[Email protected] java]# TAR-ZXVF jdk-7u79-linux-x64.tar.gz
3. setting environment variables
[Email protected] java]# Vi/etc/profile
Add the following content:
#set Java Environment
java_home=/usr/java/jdk1.7.0_79
Jre_home=/usr/java/jdk1.7.0_79/jre
Class_path=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar: $JRE _home/lib
Path= $PATH: $JAVA _home/bin: $JRE _home/bin
Export Java_home jre_home Class_path PATH
Let the changes take effect:
[Email protected] java]# Source/etc/profile
4. Verification
[Email protected] java]# java-version
Java 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 Two: with Yum Installing the JDK (CentOS)
1. See which jdk versions are available in the Yum Library
[email protected] ~]# Yum search Java|grep JDK
Ldapjdk-javadoc.x86_64:javadoc for LDAPJDK
JAVA-1.6.0-OPENJDK.X86_64:OPENJDK Runtime Environment
JAVA-1.6.0-OPENJDK-DEMO.X86_64:OPENJDK Demos
JAVA-1.6.0-OPENJDK-DEVEL.X86_64:OPENJDK Development environment
JAVA-1.6.0-OPENJDK-JAVADOC.X86_64:OPENJDK API Documentation
JAVA-1.6.0-OPENJDK-SRC.X86_64:OPENJDK Source Bundle
JAVA-1.7.0-OPENJDK.X86_64:OPENJDK Runtime Environment
JAVA-1.7.0-OPENJDK-DEMO.X86_64:OPENJDK Demos
JAVA-1.7.0-OPENJDK-DEVEL.X86_64:OPENJDK Development environment
JAVA-1.7.0-OPENJDK-JAVADOC.NOARCH:OPENJDK API Documentation
JAVA-1.7.0-OPENJDK-SRC.X86_64:OPENJDK Source Bundle
JAVA-1.8.0-OPENJDK.X86_64:OPENJDK Runtime Environment
JAVA-1.8.0-OPENJDK-DEMO.X86_64:OPENJDK Demos
JAVA-1.8.0-OPENJDK-DEVEL.X86_64:OPENJDK Development environment
JAVA-1.8.0-OPENJDK-HEADLESS.X86_64:OPENJDK Runtime Environment
JAVA-1.8.0-OPENJDK-JAVADOC.NOARCH:OPENJDK API Documentation
JAVA-1.8.0-OPENJDK-SRC.X86_64:OPENJDK Source Bundle
Ldapjdk.x86_64:The Mozilla LDAP Java SDK
2. Select a version to install
we install here 1.7 version
[email protected] ~]# Yum install JAVA-1.7.0-OPENJDK
after the installation is complete, the default installation directory is :/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64
3. setting environment variables
[Email protected] ~]# Vi/etc/profile
Add the following content:
#set Java Environment
Java_home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64
Jre_home= $JAVA _home/jre
Class_path=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar: $JRE _home/lib
Path= $PATH: $JAVA _home/bin: $JRE _home/bin
Export Java_home jre_home Class_path PATH
Let the changes take effect:
[Email protected] java]# Source/etc/profile
3. Verification
Ibid.
Note: because of the adoption of Yum Span class= "S1" > install jdk , the system takes into account multiple versions of the issue, using the Alternatives for version control. Start, the corresponding version of jdk installed in /usr/lib/jvm/ , it is registered in alternatives , in /etc/alternatives The directory will produce some links to /usr/lib/jvm/ just installed jdk version.
in the /usr/bin the corresponding files that are linked to/etc/alternatives are shown below . For example,/usr/bin will have a link file below The Java mapping relationship as follows:
/usr/bin/java->/etc/alternatives/java
/etc/alternatives/java->/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
this way, the Java command does not have to set the environment variable, it can run normally. However, if you want to set environment variables for Tomcat or other software.
Similarly, if you install a new version jdk, it will be re-linked to the latest installed jdk version. Of course, you can also use alternatives to modify the version you want to use.
specific methods can be referred to: Managing multiple versions of software using Linux alternatives
method Three: with rpm installation JDK
1. Download
[Email protected] ~]$ Curl-o http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm
2. installing using the rpm command
[Email protected] ~]# RPM-IVH jdk-7u79-linux-x64.rpm
Preparing ... ########################################### [100%]
1:JDK ###########################################[100%]
Unpacking JAR files ...
Rt.jar ...
Jsse.jar ...
Charsets.jar ...
Tools.jar ...
Localedata.jar ...
Jfxrt.jar ...
3. setting environment variables
[Email protected] java]# Vi/etc/profile
Add the following content:
#set Java Environment
java_home=/usr/java/jdk1.7.0_79
Jre_home=/usr/java/jdk1.7.0_79/jre
Class_path=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar: $JRE _home/lib
Path= $PATH: $JAVA _home/bin: $JRE _home/bin
Export Java_home jre_home Class_path PATH
Let the changes take effect:
[Email protected] java]# Source/etc/profile
4. Verification
[Email protected] java]# java-version
Java 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)
and the similar to yum installation, you can run Java commands without setting an environment variable . the rpm installation method installs the JDK to the /usr/java/jdk1.7.0_79 by default , and then link to it through the three-layer links /usr/bin, the specific link is as follows:
[Email protected] ~]# Cd/bin
[Email protected] bin]# ll|grep java
lrwxrwxrwx. 1 root root Mar 11:24 jar->/usr/java/default/bin/jar
lrwxrwxrwx. 1 root root 11:24 java-/usr/java/default/bin/java
lrwxrwxrwx. 1 root root 11:24 javac->/usr/java/default/bin/javac
lrwxrwxrwx. 1 root root 11:24 javadoc->/usr/java/default/bin/javadoc
lrwxrwxrwx. 1 root root 11:24 javaws->/usr/java/default/bin/javaws
lrwxrwxrwx. 1 root root 11:24 jcontrol->/usr/java/default/bin/jcontrol
[Email protected] bin]# cd/usr/java/
[email protected] java]# LL
Total 4
lrwxrwxrwx. 1 root root 11:24 default->/usr/java/latest
Drwxr-xr-x. 8 root root 4096 Mar 11:24 jdk1.7.0_79
lrwxrwxrwx. 1 root root 11:24 latest-/usr/java/jdk1.7.0_79
method Four: Ubuntu Installing the JDK using Apt-get
1. See which jdk versions are available in the APT library
[Email protected]:~# apt-cache Search Java|grep JDK
Default-jdk-standard Java or Java compatible development Kit
Default-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) documentation
OPENJDK-6-JDK-OPENJDK Development Kit (JDK)
OPENJDK-6-JRE-LIB-OPENJDK Java Runtime (architecture Independent libraries)
OPENJDK-6-SOURCE-OPENJDK Development Kit (JDK) source files
Openjdk-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) documentation
OPENJDK-7-JDK-OPENJDK Development Kit (JDK)
OPENJDK-7-SOURCE-OPENJDK Development Kit (JDK) source files
Uwsgi-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 JIT
OPENJDK-6-JRE-HEADLESS-OPENJDK Java Runtime, using Hotspot JIT (headless)
OPENJDK-7-JRE-OPENJDK Java Runtime, using Hotspot JIT
OPENJDK-7-JRE-HEADLESS-OPENJDK Java Runtime, using Hotspot JIT (headless)
OPENJDK-7-JRE-LIB-OPENJDK Java Runtime (architecture Independent libraries)
2. Select a version to install
[Email protected]:~# apt-get Install OPENJDK-7-JDK
3. setting environment variables
[Email protected]:~# vi/etc/profile
Add the following content:
#set Java Environment
Java_home=/usr/lib/jvm/java-1.7.0-openjdk-amd64
Jre_home= $JAVA _home/jre
Class_path=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar: $JRE _home/lib
Path= $PATH: $JAVA _home/bin: $JRE _home/bin
Export Java_home jre_home Class_path PATH
Let the changes take effect:
[Email protected]:~# source/etc/profile
4. Verification
[Email protected]:~# java-version
Java Version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.12.04.1)
OpenJDK 64-bit Server VM (build 24.79-b02, Mixed mode)
Ubuntu of the apt-get is installed in a similar way to the yum installation of CentOS and is no longer verbose here.
CentOS Install JDK