Skip to content

Instantly share code, notes, and snippets.

@1eedaegon
Last active June 6, 2022 11:46
Show Gist options
  • Select an option

  • Save 1eedaegon/2f55c61dffb28e8ba23a2bab198fe929 to your computer and use it in GitHub Desktop.

Select an option

Save 1eedaegon/2f55c61dffb28e8ba23a2bab198fe929 to your computer and use it in GitHub Desktop.
How to change python version on ubuntu 18.04

How to change python version on ubuntu 18.04

  • Use update-alternatives
  • Change python command path

Check python version and path

  1. Check python2 and python3 version
# Python2
> python --version
Python 2.7.17

# Python3
> python3 --version
Python 3.6.9
  1. Check python command location
# Python2
> which python
/usr/bin/python

# Python3
> which python3
/usr/bin/python3

Change python command path using update-alternatives

  1. Python2
> sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
  1. Python3
> sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2

Check and setup python command path

Change default python

> sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.6   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
* 2            /usr/bin/python3.6   2         manual mode
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.6   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
* 2            /usr/bin/python3.6   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

Let me check default python

> python --version
Python 3.6.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment