Note:
- I will use Python 3.10.19 for this example. Feel free to replace it with your preferred version.
- Python will be installed alongside the existing version already present in your system (i.e. It will not overwrite the default python3 binary).
- In your terminal, update the package list:
sudo apt update- Install the dependencies that will be useful for the build process:
sudo apt install -y \
libbz2-dev \
libgdbm-dev \
libdb-dev \
libffi-dev \
liblzma-dev \
libncurses5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
pkg-config \
python3-tk \
tk-dev \
uuid-dev \
zlib1g-dev-
Download your preferred version of Python from the official website: https://www.python.org/ftp/python/
-
Use wget to download the tar file:
wget https://www.python.org/ftp/python/3.10.19/Python-3.10.19.tar.xz- Extract the downloaded tar file:
tar -xvf Python-3.10.19.tar.xz- Navigate to the extracted directory:
cd Python-3.10.19Inside the extracted directory, run the following commands:
- Configure the build environment:
./configure- Compile the source code:
make- Install Python alongside the existing version already present in your system:
sudo make altinstall- Verify the installation by checking the Python version:
python3.10 --versionYou should see the installed version of Python printed in the terminal.
for example:
Python 3.10.19