The Linux operating system is known for its flexibility and configurability. One of the fantastic features that it offers is the ability to maintain multiple versions of the same software through a mechanism called ‘alternatives’. This blog post aims to walk you through the process of updating alternatives in Linux.
What are Alternatives in Linux?
The alternatives system in Linux allows you to maintain several packages that provide the same functionality simultaneously. For instance, you can have different versions of Java installed on your computer and switch between them using the alternatives system.
How to Update Alternatives
The command to update alternatives in Linux is update-alternatives. It is a powerful command-line tool that creates, removes, maintains and displays information about the symbolic links comprising the alternatives system.
Here’s how you can use it to update alternatives.
sudo update-alternatives --config java
In this example, we’re updating the alternative for Java. The –config option allows you to manually update alternatives. When you run this command, you’ll see a list of all the installed Java alternatives. You can then select the one you want to use. It’s as simple as that!
Adding a New Alternative
You can also add a new alternative using the –install option. Here’s how:
sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_241/bin/java 1
This command adds a new Java alternative located at /opt/jdk1.8.0_241/bin/java. The number ‘1’ at the end signifies the priority. If several alternatives have the same priority, the most recently added one will be used.
Removing an Alternative
To remove an alternative, you can use the –remove option. Here’s an example:
sudo update-alternatives --remove java /opt/jdk1.8.0_241/bin/java
This command removes the Java alternative located at /opt/jdk1.8.0_241/bin/java.
Conclusion
The alternatives system in Linux is a powerful feature that gives you control over different versions of software on your system. The update-alternatives command is an excellent tool for managing these alternatives. Whether you want to switch between software versions, add a new alternative, or remove an existing one, this command has got you covered.