update-alternatives命令如何使用?【20240805】

简介: 【8月更文挑战第4天】update-alternatives命令如何使用?【20240805】

update-alternatives 是一个在 Debian 和其衍生版(如 Ubuntu)中广泛使用的命令行工具,用于管理和配置系统中多个可选程序版本之间的默认选项。通过 update-alternatives 可以轻松地在不同的命令或文件之间切换,例如 Python、Java、编辑器等。

以下是 update-alternatives 命令的基本使用方法和步骤:

1. 安装替代版本

首先确保你已经安装了至少两个不同版本的软件,并且这些版本已经被正确地设置为可供选择的替代项。系统通常会自动完成这一过程,但有时需要手动执行以下操作来注册一个新的替代版本:

sudo update-alternatives --install <link> <name> <path-to-executable> <priority>
  • <link>:将创建或更新的符号链接路径。
  • <name>:替代组的名称,用于标识一组相关的可选命令。
  • <path-to-executable>:实际的可执行文件路径,即要加入到替代组中的程序版本路径。
  • <priority>:优先级数值,决定在自动模式下哪个版本会被选为默认值,数字越大表示优先级越高。

2. 列出已存在的替代项

查看某个命令的所有可用替代版本及其当前状态:

sudo update-alternatives --display <name>

3. 设置默认版本

指定一个已存在的替代版本作为默认值:

sudo update-alternatives --set <name> <path-to-executable>

或者通过交互式界面选择:

sudo update-alternatives --config <name>

运行后,系统将显示当前所有已注册的替代版本并提示用户选择一个作为默认版本。

示例

例如,如果你想管理Python版本:

# 注册Python 3.8作为Python命令的替代版本
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 10

# 注册Python 3.9作为另一个替代版本
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 20

# 查看当前Python命令的替代选项及默认设置
sudo update-alternatives --display python

# 通过交互式菜单选择默认Python版本
sudo update-alternatives --config python

请注意,上述示例可能因你的具体Linux发行版和已安装软件的实际路径而有所不同。

目录
相关文章
|
2月前
|
Ubuntu Java Linux
update-alternatives命令如何使用?
【8月更文挑战第5天】update-alternatives命令如何使用?
187 5
|
4月前
|
Ubuntu Linux Python
update-alternatives --config python 为什么不能使用
【6月更文挑战第14天】update-alternatives --config python 为什么不能使用
33 1
|
5月前
|
Ubuntu Docker 容器
sudo apt-get update失败已经解决 报错 The update command takes no arguments
sudo apt-get update失败已经解决 报错 The update command takes no arguments
159 0
|
12月前
ng update 命令的 force 选项
ng update 命令的 force 选项
|
PHP 开发者
Composer update命令是干什么的?底层原理是什么?
Composer update命令是干什么的?底层原理是什么?
1930 0
|
Perl
update-rc.d 命令
update-rc.d 命令
610 0
|
Ubuntu 网络协议 Linux
Linux - Ubuntu下执行apt-get update报错:Some index files failed to download. They have been ignored, or old ones used instead.
Linux - Ubuntu下执行apt-get update报错:Some index files failed to download. They have been ignored, or old ones used instead.
2246 0
Linux - Ubuntu下执行apt-get update报错:Some index files failed to download. They have been ignored, or old ones used instead.
|
Python
rosdep init 和rosdep update的解决方法,亲测有效
rosdep init 和rosdep update的解决方法,亲测有效
321 0
rosdep init 和rosdep update的解决方法,亲测有效
有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?
有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?
3987 0
 有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?
|
存储 SQL NoSQL
MongoDB的基本命令(insert、delete、find、update)
MongoDB的基本命令(insert、delete、find、update)
375 0
MongoDB的基本命令(insert、delete、find、update)