Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vpnwall-services/714734059fc88ff259bf6d94c41bdfb0 to your computer and use it in GitHub Desktop.
Save vpnwall-services/714734059fc88ff259bf6d94c41bdfb0 to your computer and use it in GitHub Desktop.
PYTHON 3.12 Debian Bullseye 101

PYTHON 3.12 Debian Bullseye 101

cd /tmp/
wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tgz
tar -xzvf Python-3.12.2.tgz
cd Python-3.12.2/

Install the build tools

Now, install the build tools. The build tools includes gcc, make, zlib, ssl libraries and other libraries.

sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev

If you are prompted to install other dependencies, select yes. Configure, make and make install

Run the configure script and enable Profile guided optimization (PGO) and Link Time Optimization (LTO). This can boost up speed up to 20%.

./configure --enable-optimizations

Now run make. You can make the build using nproc, which returns the number of CPUs. Ezoic

make -j `nproc`

This step can take several minutes.

make install

The default Python installation is /usr/bin. If you want to install Python under /usr/local/bin instead of overwriting the default, do this:

sudo make altinstall

This will install Python at /usr/local/bin/python3.12. To test the version, run this:

python3.12 -V

You will get this output:

Python 3.12.2

Make Python 3.12.2 the default version

To make the default version of Python 3.12.2, run this:

sudo ln -s /usr/local/bin/python3.12 /usr/local/bin/python

This creates a bunch of softlinks and links the latest Python to /usr/local/bin. ln: failed to create symbolic link '/usr/local/bin/python': File exists

If you get this error: Ezoic

ln: failed to create symbolic link '/usr/local/bin/python': File exists

that means that you already have a softlink at that location. Delete the softlink.

$ sudo rm /usr/local/bin/python

Then, repeat the softlink create command:

$ sudo ln -s /usr/local/bin/python3.12 /usr/local/bin/python

Now, verify it:

$ ls -al /usr/local/bin/python

lrwxrwxrwx 1 root root 25 Dec 26 13:08 /usr/local/bin/python -> /usr/local/bin/python3.12

Test if Python 3.12.2 is the default version

Test whether Python 3.12.2 is the default version:

$ ls -al /usr/local/bin/python

lrwxrwxrwx 1 root root 25 Dec 26 13:08 /usr/local/bin/python -> /usr/local/bin/python3.12

$ ls -al /usr/local/bin/python3.12

-rwxr-xr-x 1 root root 37195824 Feb 8 18:00 /usr/local/bin/python3.12

$ /usr/local/bin/python3.12 -V

Python 3.12.2

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