The alternatives
system (provided by the chkconfig
package in RHEL/Fedora) manages symbolic links that point to different implementations of similar commands. For example, both Sendmail and Postfix can provide the mta
group to implement the sendmail
command.
# Display information about a specific alternatives group
alternatives --display mta
While we can inspect individual groups with --display
, the system doesn't provide a straightforward way to list all available groups. This becomes problematic when:
- You need to configure an alternative but forgot the group name
- You want to audit all configurable alternatives on a system
- You're troubleshooting command conflicts
Here are three reliable methods to discover all configured alternatives:
Method 1: Using the alternatives Directory
The alternatives system stores its configuration in /var/lib/alternatives/
. Each file represents a group:
ls -1 /var/lib/alternatives/
Method 2: Using update-alternatives
On Debian-based systems, you can use:
update-alternatives --get-selections
Method 3: Comprehensive Script Approach
For cross-distribution compatibility, use this shell script:
#!/bin/bash
if command -v update-alternatives >/dev/null; then
update-alternatives --get-selections | awk '{print $1}'
elif [ -d /var/lib/alternatives ]; then
ls -1 /var/lib/alternatives/
else
echo "Could not determine alternatives location" >&2
exit 1
fi
Let's examine some common alternatives groups:
# View editor alternatives
alternatives --display editor
# Check available Java implementations
alternatives --display java
# See installed Python versions
alternatives --display python
For system administrators managing multiple servers, consider this audit script:
#!/bin/bash
echo "=== ALTERNATIVES AUDIT REPORT ==="
echo "Generated: $(date)"
echo "Hostname: $(hostname)"
echo ""
echo "=== Configured Groups ==="
if [ -d /var/lib/alternatives ]; then
for group in $(ls -1 /var/lib/alternatives/); do
echo -e "\n=== Group: $group ==="
alternatives --display "$group" | head -n 5
done
fi
- Some alternatives may be managed by package managers (like
dnf
orapt
) - Changes to alternatives persist after package upgrades
- Always test changes in a non-production environment first
The alternatives system in RHEL/Fedora (managed by the chkconfig
package) provides a way to maintain symbolic links for commands with multiple implementations. For example, both Sendmail and Postfix can provide the sendmail
command through the mta
alternatives group.
While you can inspect specific alternatives groups using:
alternatives --display mta
The fundamental problem is discovering all available groups in the first place. Unlike many Linux commands, alternatives
doesn't have a built-in listing option.
The alternatives system maintains its configuration under /var/lib/alternatives/
. Each file in this directory represents a configurable alternatives group.
Here's how to list all available alternatives groups:
ls -1 /var/lib/alternatives/
Common alternatives groups you might find include:
mta
- Mail Transport Agentjava
- Java runtimeeditor
- System default editorxdg-open
- Default application handler
For more programmatic access, you can use this bash one-liner:
for alt in $(ls -1 /var/lib/alternatives/); do
echo "=== $alt ==="
alternatives --display $alt | head -5
done
On Debian-based systems, you can use:
update-alternatives --get-selections
Understanding available alternatives is crucial for:
- System administration and configuration
- Troubleshooting command path issues
- Maintaining consistency across multiple systems
- Automating server provisioning