Easy Installation of Python 3.12 on Ubuntu 22.04

Easy Installation of Python 3.12 on Ubuntu 22.04

Introduction:

Python is a powerful and popular programming language known for its simplicity, readability, and wide range of applications. This tutorial provides two straightforward methods for installing Python 3.12 on Ubuntu 22.04.

Installation Steps:

Method 1: Installing Python 3.12 with APT

  1. System Update:
Bash
sudo apt update && sudo apt upgrade -y
  1. Add PPA Repository:
Bash
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
  1. Install Python 3.12:
Bash
sudo apt install python3.12
  1. Verify Installation:
Bash
python3.12 --version

Method 2: Installing Python 3.12 from Source

Note: This method is recommended for more experienced users.

  1. Install Prerequisites:
Bash
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
  1. Download Source Code:

Download the latest Python version from https://www.python.org/downloads/.

  1. Extract and Configure:
Bash
tar -xf Python-3.12.0.tgz
cd Python-3.12.0
./configure --enable-optimizations
  1. Compile and Install:
Bash
make -j $(nproc)
sudo make altinstall
  1. Verify Installation:
Bash
python3.12 --version

Installing Python Modules:

To install Python libraries (like numpy), use pip:

Bash
pip3.12 install numpy

Setting Python 3.12 as Default:

Bash
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.12 2
sudo update-alternatives --config python3

Tips:

  • In Method 1, Python 3.12 will automatically update.
  • In Method 2, you’ll need to repeat the compilation and installation steps to update Python.
  • For more information, refer to the official Python documentation: https://www.python.org/downloads/

 

Tags:
support hosting100