update-alternatives manages symbolic links that determine which version of a command is used when multiple versions are installed. Common on Debian/Ubuntu systems.
The system creates managed symlinks in:
/etc/alternatives/
The public command (e.g., /usr/bin/java) points to an alternatives link, which then points to the selected real binary.
update-alternatives --get-selections
See all managed commands.
sudo update-alternatives --config java
Select which Java version is default.
update-alternatives --display editor
Shows all installed alternatives and priority values.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 50
Add a new version with priority 50.
sudo update-alternatives --remove python /usr/bin/python3.11
Removes that specific binary from the group.
sudo update-alternatives --auto java
System chooses highest priority automatically.
sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
Explicitly choose version without interactive prompt.
ls -l /usr/bin/java
Verify which real binary is currently selected.
ls -l /etc/alternatives/
View managed symlinks directly.
update-alternatives --display python which python
Confirm system selection vs PATH behavior.