Linux System Package Mgmt

update-alternativesmanage default command versions

update-alternatives manages symbolic links that determine which version of a command is used when multiple versions are installed. Common on Debian/Ubuntu systems.

What it is good for

How it works

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.

10 Practical Examples

1) List all alternative groups

update-alternatives --get-selections

See all managed commands.

2) Configure a specific command interactively

sudo update-alternatives --config java

Select which Java version is default.

3) Display current selection details

update-alternatives --display editor

Shows all installed alternatives and priority values.

4) Install a new alternative manually

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 50

Add a new version with priority 50.

5) Remove an alternative

sudo update-alternatives --remove python /usr/bin/python3.11

Removes that specific binary from the group.

6) Set automatically (highest priority wins)

sudo update-alternatives --auto java

System chooses highest priority automatically.

7) Set manually (force a specific path)

sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java

Explicitly choose version without interactive prompt.

8) Check current symlink

ls -l /usr/bin/java

Verify which real binary is currently selected.

9) Inspect alternatives directory

ls -l /etc/alternatives/

View managed symlinks directly.

10) Troubleshoot conflicting versions

update-alternatives --display python
which python

Confirm system selection vs PATH behavior.

Notes & Gotchas