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

news2025/2/5 6:05:54

前言
  在基于 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 the
                               user 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 in
      automatic 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 configured
                               in 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 mode
      link best version is /usr/bin/python3.5
      link currently points to /usr/bin/python3.5
      link 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.7
      link 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 mode
      1            /usr/bin/python2.7         2         manual mode
      2            /usr/bin/python3.5         3         manual mode
    * 3            /usr/local/bin/python3.7   4         manual mode
    
    Press <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 mode
      2            /usr/bin/python3.5         3         manual mode
      3            /usr/local/bin/python3.7   4         manual mode
    
    Press <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.coloradmin.cn/o/761657.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

「2024」预备研究生mem-数学强化-整数、因数与倍数

一、整数、因数与倍数 二、带余除数 三、奇数与偶数 四、不定方程

Nature子刊-柔性薄膜上3D电极的直接激光写入

美国俄勒冈大学研究员设计了一种集成在柔性薄膜上的3D微电极阵列&#xff0c;其制造过程结合了传统的硅薄膜处理技术和双光子光刻在微米分辨率下的3D结构的直接激光书写技术&#xff0c;首次提出了一种产生高深宽比结构的方法。 发表在《自然通讯》杂志上的这项研究&#xff0c…

js实现控制台格式化打印版权信息(2023.7.16)

js代码在控制台格式化打印版权信息 2023.7.16 1、需求分析2、js实例&#xff08;浏览器版权信息&#xff09;2.1 百度一下2.1.1 js代码2.1.2 浏览器控制台输出效果 2.2 京东官网2.2.1 js代码2.2.2 浏览器控制台输出效果 2.3 EarthSDK地球页面2.3.1 js代码2.3.2 浏览器控制台输出…

【JMeter】JMeter进行JDBC数据库负载测试

JMeter进行JDBC数据库负载测试 前置准备1.创建线程组2.JDBC连接配置3.新建JDBC链接4.查看汇总报告 前置准备 此示例使用 MySQL 数据库驱动程序。 要使用此驱动程序&#xff0c;必须将其包含.jar文件&#xff08;例如 mysql-connector-java-X.X.X-bin.jar&#xff09;复制到 JM…

精选估值,解决买车卖车难题

在现代社会&#xff0c;车辆已经成为了人们生活中不可或缺的一部分。车辆的买卖交易也成为了许多人的生活中不可避免的问题。而估值则是买卖交易的过程中非常重要的一个环节。估值的准确与否直接影响到最后交易的结果。因此&#xff0c;选择一种准确便捷的估值方式就显得尤为重…

JAVA集合详解:用法、实例及适用场景

引言&#xff1a; 在JAVA编程中&#xff0c;集合是一种非常重要且常用的数据结构。通过使用集合&#xff0c;我们可以高效地组织和操作不同类型的数据。本文将深入探讨JAVA中各种集合的用法及实例&#xff0c;并介绍适用场景&#xff0c;以帮助更好地理解和应用集合。 --------…

TTX1994-可调谐激光器控制系统

花了两周时间&#xff0c;利用下班时间&#xff0c;设计了一个ITLA可调谐激光器控制系统&#xff0c;从硬件到软件。下面这个图片整套硬件系统&#xff0c;软件硬件都自己设计&#xff0c;可以定制&#xff0c;做到单片机问题也不大。相当于一套光源了 这是软件使用的界面&…

【算法】换根DP

文章目录 什么是换根DP例题分析——P3478 [POI2008] STA-Station题目列表1834. 树中距离之和⭐⭐⭐⭐⭐&#xff08;两次 dfs&#xff09;思路——冷静分析&#xff0c;列出式子算法分析⭐⭐⭐⭐⭐ 310. 最小高度树⭐⭐⭐⭐⭐2581. 统计可能的树根数目⭐⭐⭐⭐⭐C. Bear and Tr…

Coggle 30 Days of ML(23年7月)打卡

前言 最近开始关注LLM相关知识&#xff0c;但之前的NLP范式的技能不能丢。 这个练习还是比较适合我&#xff0c;感谢举办方选题&#xff0c;快速全部打卡一波。 打卡记录 任务一: 报名比赛&#xff0c;下载比赛数据集并完成读取 比赛链接&#xff1a;https://challenge.xfy…

第十六章:Understanding Convolution for Semantic Segmentation——理解用于语义分割的卷积

0.摘要 最近深度学习特别是深度卷积神经网络&#xff08;CNN&#xff09;的进展&#xff0c;显著提高了之前语义分割系统的性能。在这里&#xff0c;我们展示了通过操作与卷积相关的操作来改进逐像素的语义分割&#xff0c;这些操作在理论和实践上都具有价值。首先&#xff0c;…

【Java动态代理】—— 每天一点小知识

&#x1f4a7; J a v a 动态代理 \color{#FF1493}{Java动态代理} Java动态代理&#x1f4a7; &#x1f337; 仰望天空&#xff0c;妳我亦是行人.✨ &#x1f984; 个人主页——微风撞见云的博客&#x1f390; &#x1f433; 《数据结构与算法》专栏的文章图文并茂&am…

PyTorch 深度学习处理多维特征的输入

import numpy as np import torch import matplotlib.pyplot as plt# prepare dataset xy np.loadtxt(diabetes.csv, delimiter,, dtypenp.float32) x_data torch.from_numpy(xy[:, :-1]) # 第一个‘&#xff1a;’是指读取所有行&#xff0c;第二个‘&#xff1a;’是指从第…

Linux常用命令——eject命令

在线Linux命令查询工具 eject 用来退出抽取式设备 补充说明 eject命令用来退出抽取式设备。若设备已挂入&#xff0c;则eject命令会先将该设备卸除再退出。 eject允许可移动介质&#xff08;典型是cd-ROM、软盘、磁带、或者JAZ以及zip磁盘&#xff09;在软件控制下弹出。该…

Visual Studio 2022打包exe ,自动按日期生成文件

echo offREM 获取当前的日期和时间 set YEAR%DATE:~0,4% set MONTH%DATE:~5,2% set DAY%DATE:~8,2% set HOUR%TIME:~0,2% set MINUTE%TIME:~3,2% set SECOND%TIME:~6,2%REM 获取原始文件名 set "FilePath$(TargetPath)" for %%F in ("%FilePath%") do (set…

第46节:cesium 水面效果(含源码+视频)

结果示例: 完整源码: <template><div class="viewer"><vc-viewer @ready="ready" :logo="false"><!

【AT89C52单片机项目】99累减器

实验目的 掌握STC89C52RC单片机最小系统构成&#xff0c;最小系统由单片机芯片、时钟电路及复位电路组成。 掌握STC89C52RC单片机开发板与数码管的原理图、控制方式。 掌握对单片机I/O的复杂控制 熟练掌握C语言的设计和调试方法。 实验仪器 一套STC89C52RC开发板套件&…

Linux C/C++实现Socks5代理及Socks5协议抓包分析

如果你想在保持匿名的同时以更好的安全性和性能浏览网页&#xff0c;SOCKS5代理是一个不错的选择。 在使用互联网时&#xff0c;存在许多安全和数据隐私风险。此外&#xff0c;您可能不得不面对一些限制。想象一下&#xff0c;你想访问一个网站&#xff0c;但你根本无法访问它&…

【MySQL】从执行计划了解MySQL优化策略

文章目录 前言一、什么是执行计划1.1. 使用EXPLAIN命令1.2. 使用PROFILING 二、执行计划生成过程三、执行计划的操作符3.1. 查询计划操作符3.2. 连接操作符3.3. 辅助操作符 四、执行计划的诊断分析4.1. 使用EXPLAIN命令4.2. 检查索引4.3. 分析查询日志 五、如何分析 EXPLAIN 结…

pytorch 欠拟合和过拟合 多项式回归

欠拟合 训练误差和验证误差都有&#xff0c;还可能比较严重&#xff0c; 但它们之间仅有差距不大。 这个时候模型不能降低训练的误差&#xff0c;有可能是我们设计的模型简单了&#xff0c;表达能力不足&#xff0c; 捕获试图学习的模式比较难。由于我们的训练和验证误差之间的…

java——this、封装、static修饰成员变量、成员方法

目录 ☂️this的用法 1.访问当前对象的成员变量 2.访问当前对象的成员方法 3.调用当前对象的其他构造方法来简化代码 ☂️封装 什么是封装&#xff1f; 访问修饰限定符 ☂️static修饰成员变量 ☂️static修饰成员方法 ☂️this的用法 1.访问当前对象的成员变量 我们…