source => https://aruljohn.com/blog/install-python-debian/ <3
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-devIf 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-optimizationsNow 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 installThe 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 altinstallThis will install Python at /usr/local/bin/python3.12. To test the version, run this:
python3.12 -VYou 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/pythonThis 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/pythonThen, repeat the softlink create command:
$ sudo ln -s /usr/local/bin/python3.12 /usr/local/bin/pythonNow, verify it:
$ ls -al /usr/local/bin/pythonlrwxrwxrwx 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/pythonlrwxrwxrwx 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 -VPython 3.12.2
python -VV