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
# source ~/.bash_profile
注意需要注释掉/etc/profile文件里面的JAVA_HOM
查看及管理JAVA_HOME
/usr/local/jdk
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
[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)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。