Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Linux Commands»Update-alternatives Command: A Comprehensive Guide for Linux Users

    Update-alternatives Command: A Comprehensive Guide for Linux Users

    By RahulMay 8, 20234 Mins Read

    The update-alternatives command is a powerful tool for managing multiple versions of software on Linux systems. This tutorial will provide a comprehensive guide for mastering the update-alternatives command, including its syntax, usage, and practical examples. By the end of this tutorial, you will have a solid understanding of how to use this command to manage software alternatives in your Linux system.

    Table of Contents:

    1. Understanding the update-alternatives Command
    2. The Syntax of the update-alternatives Command
    3. Basic Usage of the update-alternatives Command
    4. Practical Examples: Configuring System Alternatives
    5. Troubleshooting Common Issues
    6. Best Practices and Tips for Using the update-alternatives Command
    7. Conclusion

    1. Understanding the update-alternatives Command

    The update-alternatives command in Linux is used to create, remove, maintain, and display information about the symbolic links that determine default commands for various software alternatives. This utility allows system administrators to easily switch between multiple versions of software packages or commands, ensuring that only one version is active at a time.

    2. The Syntax of the update-alternatives Command:

    The general syntax for the update-alternatives command is as follows:

    1
    update-alternatives [options] <command>

    Common options include:

    • –install: To install a new alternative for a specific command
    • –remove: To remove an alternative
    • –config: To configure an alternative manually
    • –auto: To configure an alternative automatically
    • –display: To display information about an alternative

    3. Basic Usage of the update-alternatives Command:

    • Installing a new alternative:
    • 1
      sudo update-alternatives --install <link> <name> <path> <priority>

      Example:

      sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 
      

    • Removing an alternative:
    • 1
      sudo update-alternatives --remove <name> <path>

      Example:

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

    • Configuring an alternative manually:
    • 1
      sudo update-alternatives --config <name>

      Example:

      sudo update-alternatives --config python 
      

    • Configuring an alternative automatically:
    • 1
      sudo update-alternatives --auto <name>

      Example:

      sudo update-alternatives --auto python 
      

    • Displaying information about an alternative:
    • 1
      update-alternatives --display <name>

      Example:

      update-alternatives --display python 
      

    4. Practical Examples: Configuring System Alternatives

    • Switching between Java versions:
    • For example, you have 2 versions of Java installed on your system. Thyen you can install the alternatives as:

      sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1100 
      sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-8-openjdk-amd64/bin/java 800 
      

      Configure the desired version:

      sudo update-alternatives --config java 
      

    • Managing different text editors:
    • Install the alternatives:

      sudo update-alternatives --install /usr/bin/editor editor /usr/bin/vim.basic 100 
      sudo update-alternatives --install /usr/bin/editor editor /usr/bin/nano 200 
      

      Configure the desired editor:

      sudo update-alternatives --config editor 
      

    5. Troubleshooting Common Issues:

    • Issue: No alternatives for a command
    • Solution: If you encounter an error stating that there are no alternatives for a command, it’s likely that the alternative has not been installed yet. Use the –install option to set up the desired alternative and then configure it as needed.

    • Issue: Invalid priority value
    • Solution: The priority value assigned to an alternative should be a positive integer. If you encounter an error related to an invalid priority value, double-check your priority assignment and ensure it’s a positive integer.

    • Issue: Broken symbolic link
    • Solution: A broken symbolic link could indicate that the target file or directory has been moved, deleted, or otherwise modified. To resolve this issue, first identify the broken link using the –display option. Next, remove the broken alternative using the –remove option, and then reinstall the alternative with the correct path using the –install option.

    • Issue: Permission denied
    • Solution: As the update-alternatives command modifies system-wide settings, you may encounter permission-related issues. To overcome this, always use ‘sudo’ to execute the command with administrative privileges.

    • Issue: Alternatives not switching as expected
    • Solution: If you find that the alternatives are not switching as expected, double-check the priority values you assigned. Remember that higher priority numbers indicate higher preference. Additionally, ensure that the alternative has been correctly configured using the –config option.

    Best Practices and Tips for Using the update-alternatives Command:

    • Always use ‘sudo’: Since the update-alternatives command modifies system-wide settings, it’s necessary to use ‘sudo’ to execute the command with administrative privileges.
    • Use descriptive priorities: Assign meaningful priority numbers to alternatives, making it easier to understand the order of preference. Higher numbers indicate higher priority.
    • Keep a clean system: Regularly review and remove unused alternatives to maintain a clean and well-organized system.
    • Test after changes: After configuring a new alternative, always test the software to ensure it’s working as expected.
    • Document your changes: Keep track of the changes you make to your system alternatives. This can help in troubleshooting and future maintenance tasks.

    Conclusion

    In this comprehensive guide, we covered the update-alternatives command in depth, including its syntax, usage, and practical examples. By mastering the update-alternatives command, you can efficiently manage multiple versions of software packages or commands on your Linux system. Remember to follow best practices and keep your system clean and well-organized. With this knowledge, you’re now well-equipped to handle system alternatives and make the most of your Linux environment.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Ignore SSL Certificate Check with Wget

    How to Ignore SSL Certificate Check with Curl

    echo Command in Linux with Practical Examples

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Create and Use Custom Python Module
    • How to Install and Use Podman on Ubuntu 22.04 & 20.04
    • Setting Up Laravel with Docker and Docker-compose
    • Setting Up Development Environments with PHP and Docker
    • Using Composer with Different PHP Versions in Linux
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.