Linux command
update-alternatives 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Add
sudo update-alternatives --install [path/to/symlink] [command_name] [path/to/binary] [priority]
Configure
sudo update-alternatives --config [java]
Remove
sudo update-alternatives --remove [java] [/opt/java/jdk1.8.0_102/bin/java]
Display
update-alternatives --display [java]
Display
update-alternatives --get-selections
说明
update-alternatives maintains symbolic links that determine default commands when multiple versions of a program are installed. It manages a directory of links in /etc/alternatives/ that point to actual program binaries. Common uses include managing multiple Java versions, editors, or compilers. Higher priority numbers are preferred in automatic mode.
参数
- --install _link_ _name_ _path_ _priority_
- Add an alternative for name with specified priority
- --config _name_
- Interactively configure alternatives for name
- --remove _name_ _path_
- Remove a specific alternative
- --display _name_
- Display information about alternatives for name
- --get-selections
- List all configured alternatives
- --set _name_ _path_
- Set the alternative non-interactively
- --auto _name_
- Switch to automatic mode (highest priority wins)
- --list _name_
- List all alternatives for a name
FAQ
What is the update-alternatives command used for?
update-alternatives maintains symbolic links that determine default commands when multiple versions of a program are installed. It manages a directory of links in /etc/alternatives/ that point to actual program binaries. Common uses include managing multiple Java versions, editors, or compilers. Higher priority numbers are preferred in automatic mode.
How do I run a basic update-alternatives example?
Run `sudo update-alternatives --install [path/to/symlink] [command_name] [path/to/binary] [priority]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --install _link_ _name_ _path_ _priority_ do in update-alternatives?
Add an alternative for name with specified priority