Howto- Install Python 3.x in Ubuntu, Debian, Fedora & Centos

Question: How to install Python 3.x in Ubuntu, Fedora &  Centos?


1- To be able to compile Python Source, you will need few packages. Open terminal and execute this command

– For Centos/Fedora

 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel

– For Ubuntu/ LinuxMint/Debian

sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev

2- Download latest release of Python

Fetch and extract source. Please refer to to ensure the latest source is used.


3- Extract and cd the extracted directory

tar -xjf Python-3.xtar.bz2 cd Python-3.x

4- Configure the build with a prefix (install dir) of /opt/python3, compile, and install.

./configure --prefix=/opt/python3 
sudo make install

Python 3 will now be installed to /opt/python3.

$ /opt/python3/bin/python3 -V Python 3.x

5- Ensure your python 3 scripts and applications query the correct interpreter.


That is all.

  • Manasij Mukherjee

    Why go into the trouble of building from source when a package “python3” is available in the repositories, directly ?

  • Mohamed Khamlichi

    Manasij Mukherjee

    u  mean  you  have  installed  python 3.2.3  from  repo.!!!   ?how  ? !!

  • Hanynowsky

    in ubuntu 12.04:
    sudo apt-get install python3
    This will install python3 and python3-minimal
    Why the heck the trouble of recompiling from source?

  • Manasij Mukherjee
  • Yhuri Kyllian

    Thanks. very useful! :)

  • Iliya

    Thanks. This helped me a lot on my Centos 6.2(x64)

  • Anonymous

    What’s with the source installs? Fedora also has python3 available and can be installed in parallel to stock 2.7.

    Just do ‘yum install python3’

  • khat33b

    i hv installed python 3.2 on ubuntu 12.04 using the steps given in the post bt when im using python command it is still showing version 2.7.3

  • Guest

    probably its because the symlink named “python”(/usr/bin/python for my system) still points to the 2.7 version try something like
    “sudo ln -s /usr/bin/python3.2 /usr/bin/python”…
    P.S. Do not recomend to do that. Its not the best solution I think… and remember – python2 and python3 are different and not the same

  • Dave

    Thanks for this. On my CentOS 6.2 x64 there was one other package that needed to be installed: tk-devel.x86_64

  • Arvind Gupta

    When I run first command sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-d
    I got Error
    eading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package libreadline5-dev is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    However the following packages replace it:
    libreadline-gplv2-dev lib64readline-gplv2-dev
    I changed libreadline5-dev to “libreadline-dev” stated dependency are installed in Linux Mint 13. Thanks for the tutorial.
    sudo apt-get install build-essential libncursesw5-dev libreadline-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-d

  • Mike

    Python 3.3.0 installed working like a champ in Stella 6.3 (CentOS). Thank you very much, this is greatly appreciated!

  • James

    If you happen to be having an issue when using this interpreter shebang, be sure you are using unix new line characters, otherwise you will get something like ‘/opt/python3/bin/python3^M: bad interpreter’

  • jasonea

    Worked great on Ubuntu 12.04.1 LTS 32-bit on Virtual Box VM, Thanks this was really helpful!