Introduction
update-alternatives
is a command-line utility in Linux that is used to manage alternative versions of packages. It is used to configure different versions of a package that can be installed on the system, and to switch between them.
How to Use
For example, there might be multiple versions of a package like Java or Python that are installed on a system, but only one version can be used at a time. update-alternatives
can be used to switch between the different versions, so that the desired version is used by default.
update-alternatives
works by creating a symbolic link from the package’s executable file to a generic name, such as “java” or “python”, that is defined in the system’s PATH. When the generic name is used, the system will automatically use the version of the package that is specified by the symbolic link.
You can use the update-alternatives
command to set the default version of a package, like so:
sudo update-alternatives --config <package>
It will list all of the available versions of the package, and prompt you to select the version that you want to use.
You can also use update-alternatives
to install a new version of a package, and configure it to be used as the default:
sudo update-alternatives --install /usr/bin/<package> <package> <path-to-new-version> <priority>
Where <package>
is the name of the package, <path-to-new-version>
is the path to the executable file of the new version, and <priority>
is an integer that represents the priority of the new version.
In summary, update-alternatives
is a command-line utility in Linux that is used to manage alternative versions of packages, and to switch between them. It makes it easy to manage multiple versions of a package installed on a system, and to switch between them as needed.
Example : Choosing version of python
Sure, here are some examples of using update-alternatives
to manage multiple versions of Python, specifically Python 3.9 and Python 3.10:
- Install Python 3.9 and 3.10:
sudo apt-get install python3.9 python3.10
- Create a new alternative for Python 3.9:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
This command creates a new alternative for Python 3.9 and sets its priority to 1.
- Create a new alternative for Python 3.10:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
This command creates a new alternative for Python 3.10 and sets its priority to 2.
- List the available alternatives for Python:
sudo update-alternatives --list python3
This command will list all the alternatives for python3 and its path and priority.
- Set the default version of Python:
sudo update-alternatives --config python3
This command will list all the available versions of Python, and prompt you to select the version that you want to use as the default.
- Switch between the versions:
sudo update-alternatives --set python3 /usr/bin/python3.9
This command will switch the default version of python3 to python3.9
Note that these examples assume that the python3.9
and python3.10
packages are already installed on your system. If they are not, you will need to install them first using apt-get
or another package manager.
Leave a Reply