实例场景应用(sunJDK1.7和sunJDK1.8切换alternatives)
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
成都创新互联公司于2013年创立,是专业互联网技术服务公司,拥有项目网站建设、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元杭锦做网站,已为上家服务,为杭锦各地企业和个人服务,联系电话:13518219792
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 Command1 /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)- 2 /home/cqs/data/jdk/jdk1.8.0_161/bin/java
网页标题:实例场景应用(sunJDK1.7和sunJDK1.8切换alternatives)
转载来源:http://scyanting.com/article/jgchip.html