Software & AppsOperating SystemLinux

How To Use update-alternatives –install Command in Ubuntu?

Ubuntu 12

In this article, we will delve into the usage of the update-alternatives --install command in Ubuntu. This command is a vital tool for managing multiple versions of a program or command on your system. It allows you to set the default version of a command, making it flexible to switch between different versions as per your requirements.

Quick Answer

The update-alternatives --install command in Ubuntu is used to create, remove, maintain, and display information about symbolic links that make up the Debian alternatives system. It allows you to set the default version of a command or program, making it easy to switch between different versions as needed.

Understanding update-alternatives

The update-alternatives command in Ubuntu is part of the dpkg package, which is the base of package management in Ubuntu. This command is used to maintain symbolic links determining default commands. It’s particularly useful when there are several versions of a command or program installed on your system.

The –install Option

The --install option is used with the update-alternatives command to create, remove, maintain and display information about the symbolic links comprising the Debian alternatives system.

Here is the general syntax of the command:

sudo update-alternatives --install link name path priority

Let’s break down the parameters:

  • link: This is the symbolic link that will be created or updated. This is the path to the command that you want to set an alternative for.
  • name: This is the name of the group of alternatives. It is used to identify a set of related commands.
  • path: This is the path to the actual executable file that the link will point to. This is the location of the command you want to set as an alternative.
  • priority: This is a number that determines the priority of the alternative. If there are multiple alternatives for a command, the one with the highest priority will be used by default.

Example Usage

Let’s take an example where we have two versions of Java installed on our system – OpenJDK 11 and Oracle JDK 8. We want to set Oracle JDK 8 as the default version.

Here’s how we can do it:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0/bin/java 1

In this command, /usr/bin/java is the link, java is the name, /usr/lib/jvm/jdk1.8.0/bin/java is the path and 1 is the priority.

Selecting a Specific Alternative

If you want to select a specific alternative from a group, you can use the --config option with the update-alternatives command.

For example:

sudo update-alternatives --config java

This command will display a list of alternatives for the Java command and prompt you to select one by entering the corresponding number.

Conclusion

The update-alternatives --install command is a powerful tool that allows you to manage multiple versions of a program or command on your Ubuntu system. By understanding how to use this command, you can easily switch between different versions of a program or command as per your requirements.

For more information about the update-alternatives command, you can execute man update-alternatives in the terminal to access the manual page or visit the Debian Alternatives System page.

What is the purpose of the `update-alternatives –install` command in Ubuntu?

The update-alternatives --install command is used to create, remove, maintain, and display information about symbolic links, allowing you to manage multiple versions of a program or command on your Ubuntu system.

How does the `update-alternatives –install` command work?

The update-alternatives --install command works by creating or updating a symbolic link to set an alternative for a specific command. You specify the path to the command you want to set as an alternative, along with a name for the group of alternatives and a priority number to determine the default alternative.

What is the purpose of the `link` parameter in the `update-alternatives –install` command?

The link parameter in the update-alternatives --install command specifies the symbolic link that will be created or updated. It is the path to the command that you want to set an alternative for.

What is the purpose of the `name` parameter in the `update-alternatives –install` command?

The name parameter in the update-alternatives --install command is used to identify a group of related alternatives. It helps in organizing and managing multiple versions of a command or program.

What is the purpose of the `path` parameter in the `update-alternatives –install` command?

The path parameter in the update-alternatives --install command specifies the path to the actual executable file that the symbolic link will point to. It is the location of the command you want to set as an alternative.

How does the `priority` parameter work in the `update-alternatives –install` command?

The priority parameter in the update-alternatives --install command is a number that determines the priority of the alternative. If there are multiple alternatives for a command, the one with the highest priority will be used by default.

How can I select a specific alternative from a group using the `update-alternatives` command?

To select a specific alternative from a group, you can use the --config option with the update-alternatives command. This will display a list of alternatives for the command and prompt you to choose one by entering the corresponding number.

Where can I find more information about the `update-alternatives` command?

For more information about the update-alternatives command, you can execute man update-alternatives in the terminal to access the manual page. You can also visit the Debian Alternatives System page for additional information.

Leave a Comment

Your email address will not be published. Required fields are marked *