Linux mint update alternatives

update-alternatives

A convenient tool for maintaining symbolic links to determine default commands.

sudo update-alternatives —config >

Изображение Шпаргалка по командам Linux, FreeBSD и MacOS

Операционная система Linux (Линукс или Лайнакс) во многом похожая на проприетарную Unix. Линукс распространён на серверах, что означает, что изучая её вы улучшаете свой навык администрирования, DevOps и программирования. Открытая …

Фото Linux

Заметки об Операционной Системе FreeBSD (фри бсд). Один из старейших Unix (Юникс), прародитель многих ОС, а также по мнению многих — самая свободная операционная система. Разработан в рамках общего проекта …

Фото FreeBSD

Полезные заметки по работе с командной строкой: bash и прочие *sh. Однострочники, скрипты, позволяющие решать большие и малые задачи администрирования и настройки Юникс систем. Zsh для современного MacOS, Bash для …

Фото Трюки Bash

Команды и инструкции терминала (консоли) Linux, MacOS, Windows и прочих операционных систем. Трюки и особенности командных оболочек, скрипты для администрирования Unix. Программирование и скриптование Windows и Linux, тонкая настройка Macos. …

Фото Терминал/Консоль

Фото Как установить пакеты из requirements.txt через pip, игнорируя ошибки

Простой способ установить список зависимостей пакета через стандартный Python менеджер пакетов. При этом чтобы pip не падал на первой же …

Фото Малоизвестные, но полезные возможности утилиты less

Команда less является одной из самых известных на ряду с cd, cp, mv и т.д. Но используется less зачастую далеко …

Фото Как найти самые большие папки и файлы в Linux

Когда кончается место на жестком диске, возникает закономерный вопрос: на что же оно было потрачено, какие файлы разрослись больше положенного?

Фото Команда grep – полезные ключи и примеры использования

У команды «grep» довольно много различных особенностей. особенно, если учесть, что с английского это «решето» – а что может войти …

Фото Как создать неизменяемый файл в Linux / MacOS / FreeBSD

Само собой, root может всё (если введёт пару команд), однако, это вполне легальный способ запретить изменение файла.

Фото Как удалить все Docker образы и контейнеры

Не всегда нужно удалять всё, но объяснение данного «рецепта» объяснит как в целом удалять образы и контейнеры.

Небольшая заметка о конструкциях Bash, в которых путается большинство новичков. А именно: >,

Фото Лучше плохо, но сейчас. Взгляд на пути развития ПО

Сейчас такие языки как Perl и Ruby чувствуют себя не лучшим образом. Но ещё 10 – 15 лет назад они …

Фото Как запустить программу в терминале в фоне, без вывода какого либо текста

Запускаем программу в терминале в фоновом режиме и разбираемся, как и почему это работает в Linux / Unix терминале.

Читайте также:  Операционная система linux ubuntu server

Источник

How to Use update-alternatives Command on Ubuntu

If you have 2 or more versions of the same command, you can use update-alternatives to set which one to use by default and also switch between them very easily. For example, let’s say, you have Python 2 and Python 3 installed on your computer. Now, you have to run a Python 2 script as follows:

Here, is the path of the Python 2 script i.e. ~/scripts/hello.py

The same way, you have to run a Python 3 script as follows:

Here, is the path of the Python 3 script i.e. ~/scripts/hello2.py

So, what if you want to access both Python 2 and Python 3 using the same command python?

Well, using update-alternatives command, you can make a new executable python (/usr/local/bin/python) and add all the available Python versions to the alternatives database. Then, you can easily set which version of Python to use by default. You can also switch between the Python versions very easily. I am going to show you how to do this practically in this article. That way, you will gain practical knowledge of how update-alternative works.

Prerequisites:

You must have Python 2 and Python 3 installed on your Ubuntu machine if you want to follow along and try out the examples in this article.

You can install Python 2 and Python 3 with the following command on Ubuntu:

Python 2 and Python 3 should be installed if not installed already. In my case, they are already installed.

Now, find the Python 2 and Python 3 interpreter path with the following commands:

As you can see, the Python 2 interpreter path is /usr/bin/python2 and Python 3 interpreter path is /usr/bin/python3. Memorize them. We will need this later.

Installing New Alternatives:

Now, you can create a new alternatives python and install Python 2 interpreter /usr/bin/python2 as an alternative with the priority 20 as follows:

NOTE: Here, /usr/local/bin/python is the binary path of the python alternatives. You can change it to some other path such as /usr/bin/python if you want. But I would suggest you place it somewhere in the /usr/local/bin/ directory as this is the directory where user-space programs should be according to the directory structure of Linux.

Читайте также:  Установка dvb в линукс

A new alternatives python should be created and Python 2 interpreter should be added there as an alternative.

The same way, install Python 3 interpreter /usr/bin/python3 as an alternative of the python alternatives and set it a priority of 40 with the following command:

Python 3 interpreter alternative should be added to the python alternatives.

Now, you can see more information about the python alternatives you’ve just created as follows:

As you can see, the python alternatives has 2 alternative commands /usr/bin/python2 (priority 20) and /usr/bin/python3 (priority 40).

Auto Mode and Alternative Priority:

Every alternatives in the update-alternatives database has 2 modes: auto and manual.

In auto mode, the alternatives selects the command/executable/alternative with the highest available priority by default.

In manual mode, you select the default command/executable/alternative for the alternatives manually.

The default mode for any alternatives is auto.

In the earlier section, you’ve seen I’ve set the priority for Python 2 interpreter (/usr/bin/python2) alternative 20 and for Python 3 interpreter (/usr/bin/python3) alternative 40. This was because I wanted to set Python 3 interpreter as the default alternative for the python alternatives. As the default mode is auto, the python alternatives selected the Python 3 interpreter alternative automatically as it has higher priority than Python 2 interpreter alternative.

As you can see, the mode (Status) is auto. The Python 3 interpreter (/usr/bin/python3) is the Best one as it has the highest priority. Also, the currently selected one is also the Python 3 interpreter (/usr/bin/python3) as it has the highest priority and the mode is auto.

As you can see, python command executes the Python 3 interpreter.

In the next section of this article, I will show you how to change the alternatives mode to manual and select a lower priority command/executable for the alternatives as well.

Changing Alternatives Command Manually:

As I have said, Python 2 won’t be automatically selected as I have set it to a lower priority. So, if you want to select a lower priority alternative, you have to do that manually.

To select Python 2 alternative manually for the python alternatives, run the following command:

Now, update-alternatives will list all the commands/alternatives you have installed for the python alternatives. In my case, it’s Python 2 and Python 3 alternatives.

Читайте также:  Linux действие при закрытии крышки ноутбука

You also have a Selection number for each version/alternative which you can use to select a version/alternative from the list. Selection number 0 is auto. Selection number other than 0 is manual.

Here, Selection number 1 is for Python 2 alternative and Selection number 2 is for Python 3 alternative.

So, to select Python 2 alternative, press 1 and then press .

Python 2 should be set as the default alternative for the python alternatives.

As you can see, the current mode is manual. Even though the Best alternative is /usr/bin/python3 (Python 3), it’s using /usr/bin/python2 (Python 2).

As you can see, python command executes the Python 2 interpreter now.

Settings Alternatives Mode to Auto:

If you want to switch to auto mode for the python alternatives again, run the following command:

Based on the priority, an alternative should be set for the python alternatives. In this case, the Python 3 alternative.

As you can see, python command executes the Python 3 interpreter.

Removing Alternative from Alternatives:

You can remove an alternative from the python alternatives.

First, list all the available alternative for the python alternatives as follows:

Now, select and copy the path of the alternative you want to remove. I am going to remove the /usr/bin/python2, the Python 2 interpreter here.

To remove the /usr/bin/python2 (Python 2 interpreter) alternative from the python alternatives, run the following command:

As you can see, the /usr/bin/python2 (Python 2 interpreter) alternative is removed from the python alternatives.

Removing All Commands from Alternatives:

You can also remove all the available alternatives from the python alternatives with the following command:

As you can see, there are no alternatives for python any more.

So, that’s how you use update-alternatives command on Ubuntu to switch between different versions of the same program or command very easily. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.

Источник

Оцените статью
Adblock
detector