0% found this document useful (0 votes)
2 views

python building

This document provides a step-by-step guide for building and installing Python from source on Ubuntu/Debian. It includes instructions for installing required dependencies, downloading the Python source code, configuring the build environment, building, and installing Python, as well as verifying the installation. Additionally, it offers an optional step to set the newly installed Python version as the default.

Uploaded by

akgamer077
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

python building

This document provides a step-by-step guide for building and installing Python from source on Ubuntu/Debian. It includes instructions for installing required dependencies, downloading the Python source code, configuring the build environment, building, and installing Python, as well as verifying the installation. Additionally, it offers an optional step to set the newly installed Python version as the default.

Uploaded by

akgamer077
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Building and Installing Python from Source on Ubuntu/Debian

===========================================================

Step 1: Open the Terminal


--------------------------
Press Ctrl + Alt + T or search for "Terminal" in your system.

Step 2: Install Required Build Dependencies


-------------------------------------------
Run the following command to install the packages needed to build Python:

sudo apt update


sudo apt install -y \
make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev \
libffi-dev liblzma-dev

Step 3: Download the Latest Python Source Code


----------------------------------------------
Visit https://www.python.org/downloads/ and get the latest stable version.
Or use wget to download directly (example uses Python 3.12.2):

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

Step 4: Extract the Archive


---------------------------
Extract the downloaded tarball:

tar -xf Python-3.12.2.tgz


cd Python-3.12.2

Step 5: Configure the Build Environment


---------------------------------------
Run the configure script to prepare the build:

./configure --enable-optimizations

Tip: You can add `--prefix=/usr/local` to install in a custom location.

Step 6: Build Python


--------------------
Build Python using `make`. You can speed this up with the `-j` flag based on CPU
cores:

make -j$(nproc)

Step 7: Install Python


----------------------
Use `make install` to install:

sudo make install

Note: You can use `make altinstall` instead to avoid overwriting the system
`python3`.

Step 8: Verify the Installation


-------------------------------
Check the installed version:

python3.12 --version

You can now use the newly installed Python version.

Optional: Set Python 3.12 as default (use with caution)


--------------------------------------------------------
To use this Python version as default, you can update alternatives:

sudo update-alternatives --install /usr/bin/python python


/usr/local/bin/python3.12 1

Then select the default:

sudo update-alternatives --config python

Done!
-----

Python is now built and installed from source on your system.

You might also like