10

I have a little problem with changing python3 to default in newly installed operating system linux Mint 19.3. It was pretty easy on Ubuntu 16.04 but now I need small help here.

So, I run

python --version

and got this

Python 2.7.15+

Than I run

python3 --version

and this was the result

Python 3.6.8

After entering this command

sudo update-alternatives --config python

I received obvious info

update-alternatives: error: no alternatives for python

Both version of python are located in /usr/bin folder. The issue occurs when I'm trying to change python3 to as a default by typing the command

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6

The terminal outputs the following

update-alternatives: --install needs <link> <name> <path> <priority>

Any help here would be welcome.

Amaresh S M
  • 2,936
  • 2
  • 13
  • 25
Michał
  • 111
  • 1
  • 1
  • 7
  • 2
    Checkout this [link](https://stackoverflow.com/questions/43062608/how-to-update-alternatives-to-python-3-without-breaking-apt) Also, I've been into the same problem before, I highly recommend that you either use an alias or use [python virtualenv](https://virtualenv.pypa.io/) Once I was so frustrated with python 2.x that I just removed it! the next thing I knew was that my gnome failed to start and hand to reinstall a whole lot of packages. – aLuViAn Jan 26 '20 at 08:04

3 Answers3

15

In your case, priority is missing, just append 1 at the end of the command like this :

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
Dark Fidis
  • 151
  • 1
  • 3
  • 3
    Update: this requires a 'priority' value at the end. I ended up running this: `sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10` to alias the 'python3' alias as `python` – drobert Sep 25 '20 at 18:12
1

@darkfidis answer is correct. But you may also need to run to set or change the default python version.

sudo update-alternatives --config python
lacostenycoder
  • 10,623
  • 4
  • 31
  • 48
0

To define python3 as your default version of python on linux, you need to add a specific line to .bashrc file located in your home directory. Here is a simple method to do so through command line interface (termianl).

Run:

$ echo "alias python='python3'" >> .bashrc
$ source .bashrc

then run python --version to check if the change has applied.

Ehsan
  • 11
  • 2
  • Works ok with ZSH too, replace `.bashrc` with `.zshrc` however this defeats the purpose of using `update-alternatives` and would require resourcing or restart shell if you decided to switch default python version in an active session. – lacostenycoder Oct 23 '22 at 20:06