Setting up a proper Python development environment is one of the first steps every developer takes when working on Ubuntu. With the release of Ubuntu 24.04 and the availability of Python 3.12, developers have access to better performance, enhanced error messages, and improved typing features. In this blog post, we’ll walk through how to install Python 3.12 Ubuntu, configure Pip (Python’s package installer), and set up a clean development environment using venv.
This guide follows the recommended practices from Vultr’s official tutorial, ensuring you're using secure and reliable installation methods.
Why Use Python 3.12 on Ubuntu 24.04?
Python 3.12 introduces several performance upgrades, such as better error locations, f-string enhancements, and reduced memory usage. Combined with Ubuntu 24.04’s updated libraries and kernel, this combo offers developers a powerful platform for everything from web development to automation and data science.
Step 1: Update Your Ubuntu 24.04 System
Start by updating your system to avoid compatibility issues:
sudo apt update && sudo apt upgrade -y
This ensures all packages are current and ready for installing new software.
Step 2: Install Required Dependencies
Before installing Python 3.12 manually, install the essential build tools and libraries:
sudo apt install -y software-properties-common build-essential libssl-dev zlib1g-dev \
libncurses5-dev libnss3-dev libreadline-dev libffi-dev libsqlite3-dev wget curl \
libbz2-dev
These packages are necessary to compile Python from source.
Step 3: Download and Install Python 3.12
Ubuntu 24.04 repositories may not yet include Python 3.12 by default, so downloading the source from Python.org is often preferred:
cd /tmp
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
tar -xvf Python-3.12.0.tgz
cd Python-3.12.0
Now configure and compile the source:
./configure --enable-optimizations
make -j$(nproc)
sudo make altinstall
Using altinstall prevents overwriting the system’s default Python version. After installation, verify:
python3.12 --version
Step 4: Install Pip for Python 3.12
Now that Python 3.12 is installed, get Pip to manage packages:
curl -sS https://bootstrap.pypa.io/get-pip.py | sudo python3.12
Check Pip’s installation:
pip3.12 --version
You now have a working setup to install and manage Python libraries using Pip with Python 3.12.
Step 5: Create and Use Virtual Environments
For clean and project-specific setups, it’s highly recommended to use venv:
python3.12 -m venv ~/myenv
source ~/myenv/bin/activate
With the virtual environment activated, all installed packages will stay isolated. You can now install libraries like Flask, Django, or NumPy:
pip install flask
To exit the environment:
deactivate
Step 6: Optional – Set Python 3.12 as Default
If you want to use Python 3.12 by default (not recommended for system-level scripts), use the update-alternatives command:
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.12 1
sudo update-alternatives --config python
Choose the Python 3.12 path when prompted.
Conclusion
With Python 3.12 now installed on Ubuntu 24.04, you’re ready to develop high-performance, modern applications with full control over your environment. This setup ensures compatibility, isolated dependencies, and an up-to-date programming experience. Refer to the official Vultr documentation for more in-depth technical references.
Whether you're building web apps, APIs, or AI solutions, Ubuntu 24.04 with Python 3.12 provides a rock-solid foundation for your development needs.
Comments