美文网首页
linux安装jdk

linux安装jdk

作者: imbird | 来源:发表于2017-05-03 14:28 被阅读0次

    由于各Linux开发厂商的不同,因此不同开发厂商的Linux版本操作细节也不一样,今天就来说一下CentOS下JDK的安装:

    方法一:手动解压JDK的压缩包,然后设置环境变量

    1.在/usr/目录下创建java目录
    [root@localhost ~]# mkdir/usr/java[root@localhost ~]# cd /usr/java
    2.下载jdk,然后解压
    [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.设置环境变量
    [root@localhost java]# vi /etc/profile
    在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

    让修改生效:
    [root@localhost java]# source /etc/profile
    4.验证JDK有效性
    [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)

    方法二:用yum安装JDK

    1.查看yum库中都有哪些jdk版本(暂时只发现了openjdk)
    [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.选择版本,进行安装
    //选择1.7版本进行安装[root@localhost ~]# yum install java-1.7.0-openjdk//安装完之后,默认的安装目录是在: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64
    3.设置环境变量
    [root@localhost ~]# vi /etc/profile
    在profile文件中添加如下内容

    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

    让修改生效
    [root@localhost java]# source /etc/profile
    4.验证(同上一方法)

    方法三:用rpm安装JDK

    1.下载rpm安装文件
    [root@localhost ~]$ curl -O http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm
    2.使用rpm命令安装
    [root@localhost ~]# rpm -ivh jdk-7u79-linux-x64.rpm
    3.设置环境变量
    [root@localhost java]# vi /etc/profile
    在打开的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

    让修改生效
    [root@localhost java]# source /etc/profile
    4.验证(同上一方法)
    注:和yum安装类似,不用设置环境变量就可以运行java命令。rpm安装方式默认会把jdk安装到/usr/java/jdk1.7.0_79,然后通过三层链接,链接到/usr/bin,具体链接如下:
    [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

    方法四:Ubuntu 上使用apt-get安装JDK

    1.查看apt库都有哪些jdk版本
    root@linuxidc:~# 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.选择版本进行安装
    root@linuxidc:~# apt-get install openjdk-7-jdk
    3.设置环境变量
    root@linuxidc:~# vi /etc/profile
    在打开的profile文件中添加如下内容

    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

    让修改生效
    root@linuxidc:~# source /etc/profile

    相关文章

      网友评论

          本文标题:linux安装jdk

          本文链接:https://www.haomeiwen.com/subject/enwktxtx.html