update-alternatives Command on Ubuntu and Debian
Master the update-alternatives command on ubuntu with step-by-step examples for managing multiple Java, Python, and editor software versions.

5 min read
Master the update-alternatives command on ubuntu with step-by-step examples for managing multiple Java, Python, and editor software versions.
- Prerequisites and Supported Releases
- Step 1: Understanding the Alternatives System Architecture
- Step 2: Displaying Information with --display and --query
In modern Linux computing, multiple software packages frequently deliver the exact same functional role or provide competing versions of a shared executable.
For example, a developer workstation might have OpenJDK 17, OpenJDK 21, and Oracle Java installed simultaneously, or multiple Python interpreters (Python 3.11 and 3.12) alongside multiple terminal text editors like Nano, Vim, and Emacs.
Rather than hardcoding absolute binary paths or breaking dependent system scripts, Debian and Ubuntu rely on the update-alternatives system.
In this guide, we master the update-alternatives command on ubuntu with practical, reproducible terminal commands for managing multiple runtime versions, querying symlink states, and registering custom binaries.
Comprehensive step-by-step administrator guide and reference manual for the update-alternatives command on Ubuntu 24.04 LTS and Debian. Explains the underlying symbolic link architecture in /etc/alternatives, querying active generic names with --display and --query, interactively selecting default programs with --config, registering new custom software binaries with --install, configuring auto vs manual modes, and removing obsolete alternatives.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A computer or server running Ubuntu 24.04 LTS, Ubuntu 22.04 LTS, or any Debian-based distribution.
- A user account with
sudoadministrative privileges for modifying system alternatives. - Basic familiarity with the terminal command line.
Step 1: Understanding the Alternatives System Architecture
The Debian alternatives system operates using a two-tier symbolic link design that decouples generic program names from specific binary implementations.
When you execute a generic command like /usr/bin/editor or /usr/bin/java, that command is not a physical binary; it is a symlink pointing to an entry in /etc/alternatives/.
The file in /etc/alternatives/ is, in turn, a symlink pointing to the actual binary (for example, /usr/bin/nano or /usr/lib/jvm/java-21-openjdk-amd64/bin/java).
This modular indirection allows administrators to switch the system-wide default software with a single command without modifying application code or shell path variables.
Step 2: Displaying Information with --display and --query
Before switching or modifying alternatives, inspect the current state and registered candidates for a specific generic name.
Use the --display flag to view all available candidates, their assigned priority values, and whether the group is operating in auto or manual mode:
Run the display command for a common alternative like editor:
# Display all registered candidates for the 'editor' alternative:
update-alternatives --display editor
# Expected output confirms:
# editor - auto mode
# link best version is /bin/nano
# link currently points to /bin/nano
# link editor is /usr/bin/editor
# /bin/ed - priority -100
# /bin/nano - priority 40
# /usr/bin/vim.basic - priority 30
# Machine-parseable query format:
update-alternatives --query editor
Step 3: Interactively Selecting Default Programs with --config
The most common use of update-alternatives is interactively choosing the default software for a generic command.
Pass the --config flag followed by the generic master name:
A numbered interactive menu lists each installed candidate; simply type the selection number and press Enter:
# Interactively select the default text editor:
sudo update-alternatives --config editor
# Terminal interactive menu snippet:
# There are 3 choices for the alternative editor (providing /usr/bin/editor).
#
# Selection Path Priority Status
# ------------------------------------------------------------
# * 0 /bin/nano 40 auto mode
# 1 /bin/ed -100 manual mode
# 2 /bin/nano 40 manual mode
# 3 /usr/bin/vim.basic 30 manual mode
#
# Press <enter> to keep the current choice[*], or type selection number: 3
Step 4: Registering Custom Program Alternatives with --install
When you install custom software manually or compile newer runtimes from source, they are not registered in the alternatives system automatically.
Use the --install option to register a new candidate into an existing or new alternative group.
The syntax requires four arguments: link (generic path), name (group name), path (real binary), and priority (higher integer wins auto mode):
Here is an example registering multiple Python versions:
# Syntax: update-alternatives --install <link> <name> <path> <priority>
# Register Python 3.12 with priority 2:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 2
# Register Python 3.11 with priority 1:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
# Verify registered python3 alternative:
update-alternatives --display python3
Step 5: Managing Slave Links (Associated Manpages and Headers)
Many applications have associated secondary files—such as manpages, compiler tools, or documentation—that must change synchronously whenever the master binary changes.
These secondary associations are called slave links.
When registering a master binary, attach slave links using the --slave flag:
When the master alternative is switched, systemd updates all associated slave links automatically:
# Register a custom editor with an associated slave manpage:
sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/myeditor 50 \
--slave /usr/share/man/man1/editor.1.gz editor.1.gz /usr/local/share/man/man1/myeditor.1.gz
Step 6: Removing Alternative Registrations with --remove
If you uninstall or delete a custom binary, remove its entry from the alternatives database to prevent broken dangling symlinks.
Use --remove to unregister a specific binary path from a group:
To remove an entire alternative group completely, use --remove-all:
# Remove a specific binary candidate from the python3 group:
sudo update-alternatives --remove python3 /usr/bin/python3.11
# Remove all candidates for an entire alternative group:
sudo update-alternatives --remove-all my_custom_tool
# Return an alternative to automatic selection mode:
sudo update-alternatives --auto editor
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
update-alternatives: error: alternative [name] can't be master: it is a slave of [other_name]
Cause: Attempting to manage a slave link directly as a top-level alternative.
Resolution: Configure the master alternative that owns the slave link instead.
update-alternatives --display [master_name]
update-alternatives: error: alternative path [path] doesn't exist
Cause: The target binary specified in the --install command does not exist on disk.
Resolution: Verify the absolute path to the binary using ls -l [path] or which [binary] before registering.
ls -la /usr/bin/python*
Shell still executes old version after update-alternatives --config
Cause: The active bash shell has cached the binary location in its hash table.
Resolution: Clear the shell binary lookup hash cache using hash -r.
hash -r
Security Best Practices and Hardening
Never register untrusted or world-writable binaries in update-alternatives, as root cron jobs and system scripts executing generic commands could be compromised.
Verify that slave links point to legitimate documentation to prevent manpage spoofing.
Exercise caution when changing the default python3 alternative on Ubuntu, as core system utilities like APT depend on specific library versions.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Install Python on Ubuntu 24.04 LTS — Learn how to manage multiple Python versions with update-alternatives.
- How to Install Java on Ubuntu 24.04 — Switch between OpenJDK 17 and OpenJDK 21 using update-alternatives.
apt Command in Linux: The Complete Package Management Guide— Comprehensive package management and repository administration.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
--config or --set), and package updates will not override the administrator's choice.sudo update-alternatives --auto [name] (e.g., sudo update-alternatives --auto editor). The system will immediately select the candidate with the highest priority./var/lib/dpkg/alternatives/, while the symbolic links reside in /etc/alternatives/.hash -r clears this cache, ensuring the shell resolves the newly symlinked binary immediately.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides


Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!