LINUX命令:update-alternatives(软件版本管理工具)

前言
  在基于 LINUX 操作系统之上安装所需开发环境组件时,可能会遇到无可避免的场景是:同一个组件,我们需要同时使用到两个或者更多的版本,比如 Java 有 1.6、1.7、1.8 等多版本,又比如 Python 有 2、3 等等,这里以 Python 组件为例,以搭建一套 Android 的 AOSP 编译环境为目标,对使用 update-alternatives 命令 管理多个组件版本 进一步详解。

update-alternatives

  • 操作系统信息

    itaso@ubuntu:~$ lsb_release -a
    No LSB modules are available.
    Distributor ID:	Ubuntu
    Description:	Ubuntu 16.04.7 LTS
    Release:	16.04
    Codename:	xenial
    itaso@ubuntu:~$ 
    
  • 使用查看 update-alternatives --help

    itaso@ubuntu:~$ update-alternatives --help
    Usage: update-alternatives [<option> ...] <command>Commands:--install <link> <name> <path> <priority>[--slave <link> <name> <path>] ...add a group of alternatives to the system.--remove <name> <path>   remove <path> from the <name> group alternative.--remove-all <name>      remove <name> group from the alternatives system.--auto <name>            switch the master link <name> to automatic mode.--display <name>         display information about the <name> group.--query <name>           machine parseable version of --display <name>.--list <name>            display all targets of the <name> group.--get-selections         list master alternative names and their status.--set-selections         read alternative status from standard input.--config <name>          show alternatives for the <name> group and ask theuser to select which one to use.--set <name> <path>      set <path> as alternative for <name>.--all                    call --config on all alternatives.<link> is the symlink pointing to /etc/alternatives/<name>.(e.g. /usr/bin/pager)
    <name> is the master name for this link group.(e.g. pager)
    <path> is the location of one of the alternative target files.(e.g. /usr/bin/less)
    <priority> is an integer; options with higher numbers have higher priority inautomatic mode.Options:--altdir <directory>     change the alternatives directory.--admindir <directory>   change the administrative directory.--log <file>             change the log file.--force                  allow replacing files with alternative links.--skip-auto              skip prompt for alternatives correctly configuredin automatic mode (relevant for --config only)--verbose                verbose operation, more output.--quiet                  quiet operation, minimal output.--help                   show this help message.--version                show the version.
    itaso@ubuntu:~$ 
    
    itaso@ubuntu:~$ update-alternatives --help
    用法:update-alternatives [<选项> ...] <命令>命令:--install <链接> <名称> <路径> <优先级>[--slave <链接> <名称> <路径>] ...在系统中加入一组候选项。--remove <名称> <路径><名称> 替换组中去除 <路径> 项。--remove-all <名称>      从替换系统中删除 <名称> 替换组。--auto <名称><名称> 的主链接切换到自动模式。--display <名称>         显示关于 <名称> 替换组的信息。--query <名称>           机器可读版的 --display <名称>.--list <名称>            列出 <名称> 替换组中所有的可用候选项。--get-selections         列出主要候选项名称以及它们的状态。--set-selections         从标准输入中读入候选项的状态。--config <名称>          列出 <名称> 替换组中的可选项,并就使用其中哪一个,征询用户的意见。--set <名称> <路径><路径> 设置为 <名称> 的候选项。--all                    对所有可选项一一调用 --config 命令。<链接> 是指向 /etc/alternatives/<名称> 的符号链接。(如 /usr/bin/pager)
    <名称> 是该链接替换组的主控名。(如 pager)
    <路径> 是候选项目标文件的位置。(如 /usr/bin/less)
    <优先级> 是一个整数,在自动模式下,这个数字越高的选项,其优先级也就越高。......
    itaso@ubuntu:~$ 
    
  • 查看替换组的信息 update-alternatives --display python

    itaso@ubuntu:~$ update-alternatives --display python
    python - manual modelink best version is /usr/bin/python3.5link currently points to /usr/bin/python3.5link python is /usr/bin/python
    /usr/bin/python2.7 - priority 2
    /usr/bin/python3.5 - priority 3
    /usr/local/bin/python3.7 - priority 4
    itaso@ubuntu:~$ 
    
    itaso@ubuntu:~$ update-alternatives --display python
    python - 手动模式link best version is /usr/bin/python3.5链接目前指向 /usr/bin/python2.7link python is /usr/bin/python
    /usr/bin/python2.7 - 优先级 2
    /usr/bin/python3.5 - 优先级 3
    /usr/local/bin/python3.7 - 优先级 4
    itaso@ubuntu:~$ 
    

    或者 假装我们知道系统自带的组件都是安装在 /usr/bin 目录下,那么我们找一下它/它们

    itaso@ubuntu:/usr/bin$ cd ~
    itaso@ubuntu:~$ pwd
    /home/itaso
    itaso@ubuntu:~$ find /usr/bin/ -name "python*"
    /usr/bin/python3
    /usr/bin/python2
    /usr/bin/python3m
    /usr/bin/python3.5
    /usr/bin/python3.5m
    /usr/bin/python2.7
    /usr/bin/python
    itaso@ubuntu:~$
    

    通过使用 find 进行条件筛选,发现系统已经带有了 python2python3
    在这里插入图片描述
    备注:python2 -> python2.7 这样的 -> 表示 软连接,这里可以把 python2 看成 Windon系统 中的 快捷方式,所以这句话的意思是 python2 真正执行的目标是 python2.7
    既然系统已经有两个 Python 的版本 ,那么已经足够用来展示多版本切换,就无需在自己手动安装其他版本的 Python 了(当然,并不阻止手动自己安装一个,一般手动安装的路径是 /usr/local/bin

  • 版本管理配置 update-alternatives --install /usr/bin/python python /usr/local/bin/python3.7 4
    为了能比较有说服力的进行版本管理,这边的验证使用了自己手动安装的 Python 3.7 版本 用于区分系统自带的 2.7 和 3.5 版本
    --install 表示向 update-alternatives 注册服务名
    /usr/bin/python 表示注册最终地址,成功后将会把命令在这个固定的目的地址做真实命令的软链,以后管理就是管理这个软链
    python 表示服务名,以后管理时以它为关联依据
    /usr/local/bin/python3.7 表示被管理的命令绝对路径
    4 表示优先级,数字越大优先级越高

  • 版本切换 update-alternatives --config python

    itaso@ubuntu:~$ sudo update-alternatives --config python
    There are 3 choices for the alternative python (providing /usr/bin/python).Selection    Path                      Priority   Status
    ------------------------------------------------------------0            /usr/local/bin/python3.7   4         auto mode1            /usr/bin/python2.7         2         manual mode2            /usr/bin/python3.5         3         manual mode
    * 3            /usr/local/bin/python3.7   4         manual modePress <enter> to keep the current choice[*], or type selection number: 1
    update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode
    itaso@ubuntu:~$ sudo update-alternatives --config python
    There are 3 choices for the alternative python (providing /usr/bin/python).Selection    Path                      Priority   Status
    ------------------------------------------------------------0            /usr/local/bin/python3.7   4         auto mode
    * 1            /usr/bin/python2.7         2         manual mode2            /usr/bin/python3.5         3         manual mode3            /usr/local/bin/python3.7   4         manual modePress <enter> to keep the current choice[*], or type selection number: 1
    itaso@ubuntu:~$ 

    备注:注意 * 号的位置

    itaso@ubuntu:~$ sudo update-alternatives --config python
    有 3 个候选项可用于替换 python (提供 /usr/bin/python).选择    	   路径                       优先级    状态
    ------------------------------------------------------------0            /usr/local/bin/python3.7   4         自动模式1            /usr/bin/python2.7         2         手动模式2            /usr/bin/python3.5         3         手动模式
    * 3            /usr/local/bin/python3.7   4         手动模式要维持当前值[*]请按<回车键>,或者键入选择的编号: 1
    update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode
    itaso@ubuntu:~$ 
    

至此,以上是在自己搭建的虚拟机系统的真实输入日志,有效的提供了从 查看操作系统查看 update-alternatives 帮助手册添加多版本管理配置 以及最后的 版本切换 操作等常用需求

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/26268.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

随手笔记——关于齐次变换矩阵的理解

随手笔记——关于齐次变换矩阵的理解 说明符号坐标系表示&#xff08;coordinate representation&#xff09;坐标系变换&#xff08;coordinate transformation&#xff09;点的操作&#xff08;point operator&#xff09; 说明 齐次变换矩阵的几种解释&#xff0c; 主要从坐…

c语言播放MP3音乐

今天学习了一下怎么用c语言播放音乐的方法&#xff0c;为了防止忘记&#xff0c;特此记录一下&#xff0c;首先就是把要播放的mp3文件保存到和要编辑的.c文件同一个目录中&#xff0c;如图所示&#xff1a; 下面就直接看代码吧&#xff1a; #include<stdio.h> #include&…

修改kernel的spi驱动,cmd+addr+data时序连续以支持spiFlash的mtd设备

【背景】 新增加的spi-nvFram芯片mb85rs4mt&#xff0c;以支持mtd设备挂载&#xff0c;发现只修改jedec无法读取芯片id&#xff0c;以及mtd设备生成。 【目的】 linux系统下支持spi-nvFram芯片。 【排查】 结合datasheet的数据传输时序需求&#xff0c;用示波器查看&#xff…

Docker 部署 Jenkins (一)

Docker 部署 Jenkins (一) 一. 安装 jenkins $ mkdir -p /home/tester/data/docker/jenkins $ vim jenkins:lts-jdk11.sh./jenkins:lts-jdk11.sh 内容 #! /bin/bash mkdir -p /home/tester/data/docker/jenkins/jenkins_homesudo chown -R 1000:1000 /home/tester/data/dock…

lua脚本语言学习笔记

Lua 是一种轻量小巧的脚本语言&#xff0c;用标准C语言编写并以源代码形式开放&#xff0c; 其设计目的是为了嵌入应用程序中&#xff0c;从而为应用程序提供灵活的扩展和定制功能。 因为我们使用redis的时候一般要写lua脚本&#xff0c;这篇文章就介绍一下lua脚本语言的基础用…

python操作Elasticsearch数据库

Elasticsearch&#xff08;ES&#xff09;,ES是一个开源的高扩展的分布式全站搜索引擎&#xff0c;是整个Elastic Stack技术栈的核心。它可以近乎实时的存储、检索数据&#xff1b;本身扩展性很好&#xff0c;可以扩展到上百台服务器&#xff0c;处理PB级别的数据。 安装好ES之…

shell数组

数组&#xff1a;数字组成的组&#xff0c;组里可以是int类型&#xff0c;string字符串 数组当中的数据类型可以由用户自定义&#xff0c;既可以是同一种&#xff0c;也可以是不同的数据类型组成的元素集合。 数组最大的作用&#xff1a;可以一次性定义多个变量 怎么来定义数…

react 实现浮动可吸附悬浮窗,悬浮球,悬浮按钮,支持拖动拖拽功能(suspend-button)

前言&#xff1a; 最近在做移动端&#xff0c;有个需求是 实现一个浮动球可拖拽&#xff0c;能吸附&#xff08;吸附到 左右两则&#xff0c;距离哪进就吸附到哪边&#xff09;。 实现过程&#xff1a; 使用 suspend-button &#xff08;但是此组件不支持 ts 和pc端&#x…

ubuntu软件商店换阿里源,并解决更新源报错-->无法验证下列签名: NO_PUBKEY 3B4FE6ACC0B21F32

目录 一、背景 二、给源文件备份 三、更新源 四、解决报错 五、继续更新源 六、完成更新&#xff0c;下载应用 一、背景 重装了个ubuntu&#xff0c;发现软件商店用不了&#xff0c;打算换源。 二、给源文件备份 1&#xff09;登录ubuntu系统&#xff0c;打开终端&…

反射(详解)

反射 什么时反射&#xff1f; 反射允许对成员变量&#xff0c;成员方法和构造方法的信息进行编程访问。 -------------------------------------------------------------------------------------- 反射(Reflection) 在运行状态中&#xff0c;对于任意一个类都能够知道这个类…

【V8】【1. 内存布局、隐藏类Hidden Class】

JavaScript 中的对象是由一组组属性和值的集合。JavaScript 对象像一个字典&#xff0c;字符串作为键名&#xff0c;任意对象可以作为键值&#xff0c;可以通过键名读写键值。 在 ECMAScript 规范中定义了数字属性应该按照索引值大小升序排列&#xff0c;字符串属性根据创建时…

FasterViT实战:使用FasterViT实现图像分类任务(一)

文章目录 摘要安装包安装timm安装 grad-cam 数据增强Cutout和MixupEMA项目结构计算mean和std生成数据集 摘要 论文翻译&#xff1a;https://blog.csdn.net/m0_47867638/article/details/131542132 官方源码&#xff1a;https://github.com/NVlabs/FasterViT 这是一篇来自英伟…