update-alternatives 使用详解

update-alternatives 命令用于处理 Linux 系统中软件版本的切换,使其多版本共存。alternatives 的管理目录 /etc/alternatives

alternatives 管理方式

$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 1120  2017 /usr/bin/python -> /etc/alternatives/python
$ ls -l /etc/alternatives/python
lrwxrwxrwx 1 root root 18 1121  2017 /etc/alternatives/python -> /usr/bin/python2.7

python 这个可执行命令实际是一个链接,指向了 /etc/alternatives/python 。而这个也是一个链接,指向了 /usr/bin/python2.7 ,这才是最终的可执行文件。alternatives 实际上是通过软链接的方式对版本进行管理。
语法:

$ 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)
<优先级> 是一个整数,在自动模式下,这个数字越高的选项,其优先级也就越高。
..........

实例

  • display 参数显示关于 Python 替换组的信息
$ 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 - 优先级 1
/usr/bin/python3.5 - 优先级 2
  • 选择候选项
$ update-alternatives --config python    

  • install 参数用于添加一个命令的link值
# 添加 python link
$ update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
# 第一个参数: --install 表示向update-alternatives注册服务名。
# 第二个参数: 注册最终地址,成功后将会把命令在这个固定的目的地址做真实命令的软链,以后管理就是管理这个软链;
# 第三个参数: 服务名,以后管理时以它为关联依据。
# 第四个参数: 被管理的命令绝对路径。
# 第五个参数: 优先级,数字越大优先级越高。

-remove 参数用于删除一个命令的link值,其附带的slave也将一起删除

$ update-alternatives –remove python /usr/bin/python2.7

转载于:https://www.jianshu.com/p/4d27fa2dce86

Resolving the 'multiple definition of yylloc' Error 1 2 3 The multiple definition of 'yylloc' error occurs during the compilation process, typically when building the Linux kernel or related projects. This error indicates that the yylloc symbol is defined in multiple places, causing a conflict. Example /usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of 'yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here collect2: error: ld returned 1 exit status Solution 1: Modify Source Code One common solution is to modify the source code to declare yylloc as an external variable 1 . Steps: Open the file scripts/dtc/dtc-lexer.lex.c. Find the line YYLTYPE yylloc;. Change it to extern YYLTYPE yylloc;. Example: // Original line YYLTYPE yylloc; // Modified line extern YYLTYPE yylloc; Solution 2: Use an Older GCC Version The error can also be caused by using a newer version of GCC (e.g., GCC 10 or later). Downgrading to an older version like GCC 9 can resolve the issue 2 . Steps: Install GCC 9. Set it as the default compiler. Example: sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 Solution 3: Clean and Rebuild Sometimes, old object files can cause this issue. Cleaning the build directory and rebuilding can help 3 . Steps: Clean the build directory. Rebuild the project. Example: make clean make By following these steps, you can resolve the multiple definition of 'yylloc' error and successfully compile your project. Learn more 1 github.com 2 blog.youkuaiyun.com 3 github.com
04-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值