How to Install Python 3.6.1 in Ubuntu 16.04 LTS

This quick tutorial is going to show you how to install the latest Python 3.6.1 in Ubuntu 16.04 LTS via PPA.

Ubuntu 16.04 comes with both Python 2.7 and Python 3.5 by default. You can install Python 3.6 along with them via a third-party PPA by doing following steps:

1. Open terminal via Ctrl+Alt+T or searching for “Terminal” from app launcher. When it opens, run command to add the PPA:

sudo add-apt-repository ppa:jonathonf/python-3.6

Type in your password (no visual feedback due to security reason) when it asks and hit Enter.

2. Then check updates and install Python 3.6 via commands:

sudo apt-get update

sudo apt-get install python3.6

Now you have three Python versions, use python command for version 2.7, python3 for version 3.5, and/or python3.6 for version 3.6.1.

3. To make python3 use the new installed python 3.6 instead of the default 3.5 release, run following 2 commands:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1

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

Finally switch between the two python versions for python3 via command:

sudo update-alternatives --config python3

After selecting version 3.6:

python3 -V

UPDATE: due to this bug, gnome-terminal won’t launch after step 3, a workaround is running following commands to recreate the symlink:

sudo rm /usr/bin/python3

sudo ln -s python3.5 /usr/bin/python3

By Ji m

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to remind me outdated tutorial! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

25 comments

  1. I tried it and it works fine, but I was not able to correctly install python3-dev module, which then prevents to install some other modules.

  2. After following above procedures i went to install my own selection as follows:

    apt-get install python3.6 idle-python3.6 python3.6-doc python3.6-examples libpython3.6 libpython3.6-stdlib python-clang-3.6 python-lldb-3.6 libpython3.6-dbg python3.6-venv

    no error after the above command above.

    Linux ubuntu-net 4.4.0-93-generic #116-Ubuntu SMP Fri Aug 11 21:17:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

    to make python3.6 as the default, remove the rest of pythons and create a soft link to the python3.6:

    ls /usr/bin/python*
    /usr/bin/python /usr/bin/python2.7 /usr/bin/python3.5 /usr/bin/python3.6 /usr/bin/python3m
    /usr/bin/python2 /usr/bin/python3 /usr/bin/python3.5m /usr/bin/python3.6m

    rm /usr/bin/python
    ln -s /usr/bin/python3.6 /usr/bin/python
    ln -s /usr/bin/python3.6m /usr/bin/pythonm

    python
    Python 3.6.2 (default, Jul 20 2017, 08:43:29)
    [GCC 5.4.1 20170519] on linux
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>>

    THANKS FOR THE HELP…!

  3. Hi, Thank you. Single point of knowledge for all what is required in relevance of basic python installation.

  4. what error E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)
    E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

    what is problem

  5. After changing python default to python3.6 … Now I am not able to launch Terminal … What to do ? … please help anyone

  6. Reply anyone …. My Terminal , Startup Disc Creator etc are not being launched … Help me..

      1. After fixing bug as you have given the workaround, then python runs in the default version of 2.7.12 itself. Although i have installed the version 3.6.3 and even selected the same version manually.

  7. Excellent post and tuto.
    Thanks a lot.
    I have now 3 version of Python working on my Ubuntu 16.04LTS x64.

  8. hello sir,thanks for the post.However after following all the steps including the update step,i am getting below error for command python3 -v

    # /usr/lib/python3.5/__pycache__/_collections_abc.cpython-35.pyc matches /usr/lib/python3.5/_collections_abc.py
    # code object from ‘/usr/lib/python3.5/__pycache__/_collections_abc.cpython-35.pyc’
    import ‘_collections_abc’ #
    import ‘os’ #
    # /usr/lib/python3.5/__pycache__/_sitebuiltins.cpython-35.pyc matches /usr/lib/python3.5/_sitebuiltins.py
    # code object from ‘/usr/lib/python3.5/__pycache__/_sitebuiltins.cpython-35.pyc’
    import ‘_sitebuiltins’ #
    # /usr/lib/python3.5/__pycache__/sysconfig.cpython-35.pyc matches /usr/lib/python3.5/sysconfig.py
    # code object from ‘/usr/lib/python3.5/__pycache__/sysconfig.cpython-35.pyc’
    import ‘sysconfig’ #
    # /usr/lib/python3.5/__pycache__/_sysconfigdata.cpython-35.pyc matches /usr/lib/python3.5/_sysconfigdata.py
    # code object from ‘/usr/lib/python3.5/__pycache__/_sysconfigdata.cpython-35.pyc’
    # /usr/lib/python3.5/plat-x86_64-linux-gnu/__pycache__/_sysconfigdata_m.cpython-35.pyc matches /usr/lib/python3.5/plat-x86_64-linux-gnu/_sysconfigdata_m.py
    # code object from ‘/usr/lib/python3.5/plat-x86_64-linux-gnu/__pycache__/_sysconfigdata_m.cpython-35.pyc’
    import ‘_sysconfigdata_m’ #
    import ‘_sysconfigdata’ #
    # /usr/lib/python3.5/__pycache__/sitecustomize.cpython-35.pyc matches /usr/lib/python3.5/sitecustomize.py
    # code object from ‘/usr/lib/python3.5/__pycache__/sitecustomize.cpython-35.pyc’
    # /usr/lib/python3/dist-packages/__pycache__/apport_python_hook.cpython-35.pyc matches /usr/lib/python3/dist-packages/apport_python_hook.py
    # code object from ‘/usr/lib/python3/dist-packages/__pycache__/apport_python_hook.cpython-35.pyc’
    import ‘apport_python_hook’ #
    import ‘sitecustomize’ #
    import ‘site’ #
    Python 3.5.2 (default, Nov 23 2017, 16:37:01)
    [GCC 5.4.0 20160609] on linux
    Type “help”, “copyright”, “credits” or “license” for more information.
    # extension module ‘readline’ loaded from ‘/usr/lib/python3.5/lib-dynload/readline.cpython-35m-x86_64-linux-gnu.so’
    # extension module ‘readline’ executed from ‘/usr/lib/python3.5/lib-dynload/readline.cpython-35m-x86_64-linux-gnu.so’
    import ‘readline’ #
    import ‘atexit’ #
    # /usr/lib/python3.5/__pycache__/rlcompleter.cpython-35.pyc matches /usr/lib/python3.5/rlcompleter.py
    # code object from ‘/usr/lib/python3.5/__pycache__/rlcompleter.cpython-35.pyc’
    import ‘rlcompleter’ #
    >>>
    please tell me the fix for it..thanks again

  9. thanks. It’s really helpful.
    but after this post terminal not open but after chng usr/bin/gnome-terminal python3.6 to python3 that terminal working fine.
    thank you again.

Comments are closed.

Exit mobile version