通过alternatives进行多版本间切换
上周在学习单点登录安装CAS Overlay Template要使用指定版本,当时机器上安装了多个版本的jdk使用alternatives命令进行了切换. 如果需要在多个版本应用间切换并进行管理可以使用这个命令。 alternative 前身是 Debian Linux的一个用 Perl实现的工具 update-alternatives 后续Red Hat重写了并重新命名使用在 Red Hatand CentOS版本中. alternative统一了有多个版本应用,但在UNIX中更认可通过环境变量来设置 通常定义在 /etc/profile 或 $HOME/.profile 下面用一个例子演示一下 如果有有一个应用 em ,他的新版本 nem, 由于习惯原因, 我们更习惯敲em, 可以通过下面步骤设置一下 创建 先创建两个脚本做为代表em nem应用 [root@centosgpt alternatives]# cat em #!/bin/bash echo " This is em " [root@centosgpt alternatives]# cat nem #!/bin/bash echo " This is nem " 生成一个alternative需要下面四个要素: alternatives --install <link> <name> <path> <priority> link : 统一应用名称,一个链接文件 name : alternative 的名称便于记忆 path : 实际版本的路径 priority :优先级 [root@centosgpt alternatives]# sudo alternatives --install /usr/bin/em uemacs /root/alternatives/em 1 [root@centosgpt alternatives]# sudo alternatives --install /usr/bin/em uemacs /root/alternatives/nem 99 [root@centosgpt alternatives]# alternatives --config uemacs There are 2 programs which provide 'uemacs'. Selection Command ----------------------------------------------- + 1 /root/alternatives/em * 2 /root/alternatives/nem 验证 [root@centosgpt ~]# em This is nem [root@centosgpt ~]# alternatives --config uemacs There are 2 programs which provide 'uemacs'. Selection Command ----------------------------------------------- 1 /root/alternatives/em *+ 2 /root/alternatives/nem Enter to keep the current selection[+], or type selection number: 1 [root@centosgpt ~]# em This is em 移除 alternatives --remove <name> <path> ...