I need to install the latest version of Python on Debian . Already changed the repositories in sources.list to test and updated, but still not the latest version of Python . I do not want to update the whole system from unstable or experimental repositories.

Is it possible to install only one of them from Python , or to install from the archive from the official site ?

1 answer 1

No package - you can build from source.

Consider a global installation from scratch (without discussing utilities such as pyenv ), for the Debian 8 version . You need sudo :

 su <root_user> apt-get install sudo 

You will need to update the list of repositories with packages. An example of a list for a version other than 8 can be taken from here . You need to open the /etc/apt/sources.list file in any text editor ( sudo vi /etc/apt/sources.list ) and add to jessie:

 deb http://httpredir.debian.org/debian jessie main deb-src http://httpredir.debian.org/debian jessie main deb http://httpredir.debian.org/debian jessie-updates main deb-src http://httpredir.debian.org/debian jessie-updates main deb http://security.debian.org/ jessie/updates main deb-src http://security.debian.org/ jessie/updates main 

Perhaps in the same file you will need to comment out ( # ) the line (if any) with deb:cdrom [...] so that the packages are not searched on the disk.

Then sudo apt-get update update the list of packages.

You need a C compiler from the GNU Compiler Collection package: gcc and make . Both packages are in build-essential

 sudo apt-get install build-essential 

There are also optional, but important dependencies: zlib and ssl

 sudo apt-get install openssl sudo apt-get install zlib1g-dev 

Without zlib, it will not work with zip archives, without ssl you cannot open https: // addresses (and this is at least).

The last dependency is checkinstall - sudo apt-get install checkinstall .

Then select any folder and Python 3.6 will be built in it. For another version, you will need to change the link and file name to the corresponding version. Explanations on configure --enable-optimizations are in the README .

 wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz tar xvf Python-3.6.0.tgz cd Python-3.6.0 ./configure --enable-optimizations make -j4 make test sudo checkinstall -D --pkgname=python3_6 make altinstall 

Argument -j4 will allow parallel compilation on 4 cores - you can specify any amount available to the system and this will significantly speed up the build.

Checkinstall instead of copying to folders will directly create a .deb package and then install it. The main advantage - then it (the package) is very easy to remove. Otherwise, you need to know what and where it was installed to remove everything manually. During the execution of the last command, you will be asked to configure the package - you can skip the step and leave all the default values. The pkgname argument should not conflict with existing packages.

The altinstall parameter will not overwrite the python3 version by default (system and not only utilities can use it), but will create only the pythonX.X binary.

The package was installed automatically, you can remove it with the command

 dpkg -r python3-6 

The installed interpreter can be started python3.6 command python3.6

  • What does altinstall do and why not checkinstall? - andreymal
  • @andreymal, altinstall does not overwrite the python command, it creates only pythonX.X - docs.python.org/3.6/using/unix.html#building-python . I forgot about checkinstall (!) - I’ll update my answer. - m9_psy