linux下安装JDK
Posted George93_部落格
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux下安装JDK相关的知识,希望对你有一定的参考价值。
方法一:手动安装jdk的安装包,配置环境变量
1.在/usr/目录下创建java目录
[[email protected] ~]# mkdir/usr/java [[email protected] ~]# cd /usr/java
2.下载安装包并解压
[[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.设置环境变量
[[email protected] java]# vi /etc/profile
进入vi编辑模式,加入如下代码:
#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
让修改生效:
[[email protected] java]# source /etc/profile
4.验证
[[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)
方法二:用yum安装JDK(CentOS)
1.查看yum库中都有哪些jdk版本
[[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.选择版本,安装
[[email protected] ~]# yum install java-1.7.0-openjdk
注:默认的安装目录是在: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64
3.设置环境变量
[[email protected] ~]# vi /etc/profile
进入vi编辑模型,增加:
#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
让修改生效:
[[email protected] java]# source /etc/profile
3.验证,同上
方法三:用rpm安装JDK
1.下载
[[email protected] ~]$ curl -O http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm
2.使用rpm命令安装
[[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.设置环境变量
[[email protected] java]# vi /etc/profile
进入VI编辑,添加:
#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
让修改生效:
[[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)
方法四:Ubuntu 上使用apt-get安装JDK
1.查看apt库都有哪些jdk版本
[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.选择版本进行安装
[email protected]:~# apt-get install openjdk-7-jdk
3.设置环境变量
[email protected]:~# vi /etc/profile
添加如下内容:
#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
让修改生效:
[email protected]:~# source /etc/profile
4.验证
[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)
以上是关于linux下安装JDK的主要内容,如果未能解决你的问题,请参考以下文章