Do sudo update-alternatives --remove-all gccc.

Answer from fkraiem on askubuntu.com
🌐
Linux Hint
linuxhint.com › update_alternatives_ubuntu
How to Use update-alternatives Command on Ubuntu – Linux Hint
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 ...
Top answer
1 of 7
61

replace

[bash:~] $ sudo update-alternatives --install /usr/bin/python python \
/usr/bin/python2.7 2

[bash:~] $ sudo update-alternatives --install /usr/bin/python python \
/usr/bin/python3.5 3

with

[bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
/usr/bin/python2.7 2

[bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
/usr/bin/python3.5 3

e.g. installing into /usr/local/bin instead of /usr/bin.

and ensure the /usr/local/bin is before /usr/bin in PATH.

i.e.

[bash:~] $ echo $PATH
/usr/local/bin:/usr/bin:/bin

Ensure this always is the case by adding

export PATH=/usr/local/bin:$PATH

to the end of your ~/.bashrc file. Prefixing the PATH environment variable with custom bin folder such as /usr/local/bin or /opt/<some install>/bin is generally recommended to ensure that customizations are found before the default system ones.

2 of 7
47

Per Debian policy, python refers to Python 2 and python3 refers to Python 3. Don't try to change this system-wide or you are in for the sort of trouble you already discovered.

Virtual environments allow you to run an isolated Python installation with whatever version of Python and whatever libraries you need without messing with the system Python install.

With recent Python 3, venv is part of the standard library; with older versions, you might need to install python3-venv or a similar package.

$HOME~$ python --version
Python 2.7.11

$HOME~$ python3 -m venv myenv
... stuff happens ...

$HOME~$ . ./myenv/bin/activate

(myenv) $HOME~$ type python   # "type" is preferred over which; see POSIX
python is /home/you/myenv/bin/python

(myenv) $HOME~$ python --version
Python 3.5.1

A common practice is to have a separate environment for each project you work on, anyway; but if you want this to look like it's effectively system-wide for your own login, you could add the activation stanza to your .profile or similar.

Top answer
1 of 2
9

I would try cleaning it up manually. I've never done this so make sure you backup beforehand.

  • Remove the link from /etc/alternatives
  • Remove the relevant file from the admin directory
    • /var/lib/dpkg/alternatives/ on ubuntu (debian may be the same but check the man pages under the FILES section)
    • /var/lib/alternatives/ on CentOS 6&7
2 of 2
11

Removing them manually resulted in ... is already managed by ... error in my case. Aside from that, the manual removal also didn't scale, as i've had added multiple multiple alternatives for the centralized symlink. It's just a mess.
When it comes to either update-alternatives or alternatives, they both provide the --remove and --remove-all flags. As for the former flag, it only removes one single alternative of the link group. For example

$ update-alternatives --list python3
/usr/bin/python3.8
/usr/bin/python3.9

$ sudo update-alternatives --remove python3 /usr/bin/python3.9

$ update-alternatives --list python3
/usr/bin/python3.8

The form of the --remove flag goes by update-alternatives --remove symlink-generic-name /path/to/one/executable/alternative

However, if you want to outright erase the generic name with all of its associated alternatives all at once, then --remove-all is the way to go.

$ update-alternatives --list python3
/usr/bin/python3.8
/usr/bin/python3.9

$ sudo update-alternatives --remove-all python3

$ update-alternatives --list python3
update-alternatives: error: no alternatives for python3

$ update-alternatives --query python3
update-alternatives: error: no alternatives for python3
Top answer
1 of 1
6

Python 2.X packages are named differently than Python 3.X packages in the default Ubuntu repositories, python-... for Python 2.X packages vs. python3-... for Python 3.X packages. The command to start the Python interpreter follows a similar pattern, python for the default Python 2.X version vs. python3 for the default Python 3.X version.

Don't remove the default Python 3.x version because removing it can break a lot of things like the terminal, the Software app and many other apps. For more information see this question: Removed Python 3 and now Ubuntu Software Center, terminal and other applications don't work. The good news is that even if you break those things it is possible to restore the original Python 3.x version by booting Ubuntu into recovery mode, and then Ubuntu will work normally again.

Instead of replacing the default Python 3.x version entirely the recommended way of installing another Python 3.x version is to keep the existing Python 3 and install the new Python 3 version alongside it. Then you can use a program called update-alternatives to select which one of the Python versions you want to use.

Add Python 3.8 to update-alternatives so that you can switch between Python 3.5 and Python 3.8 by running update-alternatives --config python3.

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8
update-alternatives --config python3

After you are done using Python 3.8 you can switch the it back to the default Python 3.5 version.

  • List installed versions of Python: update-alternatives --list python

  • Switch between Python versions: update-alternatives --config python

    From the terminal command-line Press <enter> to keep the current choice[*], or type selection number:

🌐
GitHub
gist.github.com › patrickmmartin › 5b6b2ddecd29d6a1b2ffee2d8eea31ec
update-alternatives for python3 on Ubuntu · GitHub
ls -larth `which python`* -rwxr-xr-x 2 root root 4.3M Nov 17 19:23 /usr/bin/python3.5 -rwxr-xr-x 1 root root 3.4M Nov 19 09:35 /usr/bin/python2.7 lrwxrwxrwx 1 root root 24 Feb 5 09:36 /usr/bin/python -> /etc/alternatives/python ... sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2 $ sudo update-alternatives --config python There are 2 choices for the alternative python (providing /usr/bin/python).
🌐
LinuxVox
linuxvox.com › blog › ubuntu-using-alternatives
Mastering Ubuntu Using Alternatives: A Comprehensive Guide — linuxvox.com
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 10 · Here, /usr/bin/python is the link name, python is the name of the alternative, /usr/bin/python3.9 is the path to the executable, and 10 is the priority. If you want to remove an alternative from the system, you can use the following command:
🌐
Brentknigge
brentknigge.com › notes › linux › linux-update-alternatives
Update Alternatives
You are presented with a menu to change the application you wish to have associated with python. In this case I will enter 1 so that python2 is now my default interpreter. ... Removing an entry is done with the following syntax. sudo update-alternatives --remove my_name application_path
🌐
Ask Ubuntu
askubuntu.com › questions › 1099776 › question-about-python-mapping-etc-alternatives-python
16.04 - Question about Python mapping (/etc/alternatives/python) - Ask Ubuntu
I didn't really know what I was ...ge.com/questions/410579/change-the-python3-default-version-in-ubuntu ... $ sudo update-alternatives --config python #Will show you an error: ......
Find elsewhere
🌐
TecAdmin
tecadmin.net › linux-update-alternatives-command
Update-alternatives Command: A Comprehensive Guide for Linux Users – TecAdmin
April 26, 2025 - Next, remove the broken alternative using the –remove option, and then reinstall the alternative with the correct path using the –install option. Solution: As the update-alternatives command modifies system-wide settings, you may encounter permission-related issues.
🌐
Ask Ubuntu
askubuntu.com › questions › 1423289 › how-to-revert-alternatives-to-default-python2-on-18-04
python3 - How to revert alternatives to default python2 on 18.04? - Ask Ubuntu
sudo rm /etc/alternatives/python sudo ln -s /usr/bin/python2 /etc/alternatives/python ... The usual interactive usage would be sudo update-alternatives --config python, then follow the on-screen instructions - did you try that?
🌐
GitHub
gist.github.com › 6910dd256f989abb41af30a8eeb01237
Update alternatives syntax for changing from python2.7 to python3.7 · GitHub
Update alternatives syntax for changing from python2.7 to python3.7 - update-alternatives-python.sn
🌐
LinuxConfig
linuxconfig.org › home › how to change from default to alternative python version on debian linux
How to change from default to alternative Python version on Debian Linux
December 7, 2023 - For example let’s remove python2.7 version: # update-alternatives --remove python /usr/bin/python2.7 update-alternatives: removing manually selected alternative - switching python to auto mode update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
🌐
GitHub
gist.github.com › GrowtopiaJaw › 7c5b7556c9b9a48aa68fe063107e1a5d
update-alternatives for python2 and python3 in Ubuntu 16.04.x · GitHub
We have 2 options available, python2.7 and python3.5 (These are default pythons that came with Ubuntu) ... sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 sudo update-alternatives --install /usr/bin/python python ...
🌐
Programmersought
programmersought.com › article › 21324862566
Use update-alternatives to modify the Python version under ubuntu - Programmer Sought
update-alternatives: removing manually selected alternative - switching python to auto mode update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python (python) in auto mode ... Note: This method is only available for the Debian Linux system. First, check if there is a Python optional and add If you prompt the following information, there is no option, we need to add it yours... update-alternatives command in ubuntu update-alternatives --install link name path priority Usage example: Create a soft connection named gcc in the /usr/bin directory, pointing to /etc/alternatives/g...