Table of Contents
As you may know, Debian repositories update very slowly. At the time of writing, Python release versions are at 2.7.12 and 3.5.2, but in Debian 8 repositories you can find only 2.7.9 and 3.4.2. On Debian 7, versions in the repository are even older (2.7.3 and 3.2.3), both shipped in 2012.
This tutorial teaches you how to build Python from source and install the latest version. I assume you are using Debian 7 or 8. We will be obtaining the source code from the official Python FTP.
First, let’s check your currently installed version of Python. Run this command on your terminal:
You will see something like this:
Commands below must be performed by the root user.
Obtain Python source code
The following commands will load an archive with Python sources for version 2.7.12 to the home directory, unpack it, and switch to the directory with unpacked files:
cd /home wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz tar xf Python-2.7.12.tar.xz cd ./Python-2.7.12
Pay attention to the name of the folder with unpacked files. It will be the same as the archive name (without the archive extension).
Now we can build the updated Python binaries:
./configure make make install
Switch to the new version
If you check the Python version now, you still see the same old one. So we need to point the default Python interpreter path to the new python binary, which was installed to
update-alternatives --install /usr/bin/python python /usr/local/bin/python 10
Now you will see the installed version:
python --version Python 2.7.12
Differences for Python 3
Python 3 can be updated in the same fashion, with one simple difference – you need to specify
python3 instead of
python. Note that Python 3 doesn’t come pre-installed on Debian 7.
Switch to new version:
update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3 10
When updating Python 3, remember to choose a corresponding archive from the Python FTP site.
Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!