温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

实例场景应用(sun JDK1.7和sun JDK1.8切换alternatives)

发布时间:2020-07-27 03:49:49 来源:网络 阅读:370 作者:caoqishun 栏目:系统运维

Java运用于执行java程序(java运行环境)
Javac运用于java程序编译(java程序开发环境)
步骤二:alternatives安装JDK
#alternatives --install /usr/bin/java java /usr/local/jdk版本/bin/java 1
#alternatives --install /usr/bin/javac java /usr/local/jdk版本/bin/javac 2
步骤二:查看可用的版本信息
#alternatives --display java
#alternatives --display javac
步骤三:切换java版本
#alternatives --config java
#alternatives --config javac
删除jdk版本(可选项,需要删除时使用--remove)
#alternatives --remove java /usr/local/java/jdk版本/bin
#alternatives --remove javac /usr/local/java/jdk版本/bin
步骤四:修改当前用户的jdk运行环境
#echo export JAVA_HOME=/usr/bin/java >>~/.bash_profile

echo export PATH=$PATH:$JAVA_HOME/bin >>~/.bash_profile

    # source ~/.bash_profile

注意需要注释掉/etc/profile文件里面的JAVA_HOM
查看及管理JAVA_HOME

echo $JAVA_HOME

/usr/local/jdk

java -version

java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

#实例

[cqs@centos7 jdk]$echo ’export JAVA_HOME=/usr/bin/java’ >>~/.bash_profile
[cqs@centos7 jdk]$ echo ‘export PATH=$PATH:$JAVA_HOME/bin’ >>~/.bash_profile
[cqs@centos7 jdk]$ source ~/.bash_profile

注意需要注释掉/etc/profile文件里面的JAVA_HOM

[cqs@centos7 jdk]$ echo $JAVA_HOME

/usr/bin/java

[cqs@centos7 jdk]$ echo $PATH

/usr/local/bin:/usr/bin:/usr/local/mysql/bin:/usr/local/sbin:/usr/sbin:/home/cqs/.local/bin:/home/cqs/bin:/usr/bin/java/bin

步骤一:alternatives安装JDK1.7(链接路径【link】:/usr/bin/java  链接名【name】:java 应用程序JAVA实际路径【path】:/home/cqs/data/jdk/jdk1.7.0_80/bin/java  优先级【priority】 :1)
    [cqs@centos7 jdk]$ sudo alternatives --install /usr/bin/java java ~/data/jdk/jdk1.7.0_80/bin/java 1
    [cqs@centos7 jdk]$ sudo alternatives --config java

There is 1 program that provides 'java'.
Selection Command

*+ 1 /home/cqs/data/jdk/jdk1.7.0_80/bin/java
Enter to keep the current selection[+], or type selection number:

[cqs@centos7 jdk]$ java -version

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

alternatives安装JDK1.8

[cqs@centos7 jdk]$ sudo alternatives --install /usr/bin/java java ~/data/jdk/jdk1.8.0_161/bin/java 2
[cqs@centos7 jdk]$ sudo alternatives --config java

There are 2 programs which provide 'java'.
Selection Command

  • 1 /home/cqs/data/jdk/jdk1.7.0_80/bin/java

    • 2 /home/cqs/data/jdk/jdk1.8.0_161/bin/java
      Enter to keep the current selection[+], or type selection number: 2

    [cqs@centos7 jdk]$ java -version

    java version "1.8.0_161"
    Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
    [cqs@centos7 jdk]$ sudo alternatives --config java
    There are 2 programs which provide 'java'.
    Selection Command

    1 /home/cqs/data/jdk/jdk1.7.0_80/bin/java
    *+ 2 /home/cqs/data/jdk/jdk1.8.0_161/bin/java
    Enter to keep the current selection[+], or type selection number: 1

    [cqs@centos7 jdk]$ java -version

    java version "1.7.0_80"
    Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI