Although modern Linux distributions provide graphical interfaces, software installation and management are significantly faster and more flexible via the command line. Python, a versatile programming language, can be installed on Ubuntu 24.04 in multiple ways depending on your needs.
Check if Python is already installed
Open the terminal and run:
If Python is installed, it will return a version like Python 3.12.x. If not, proceed with installation.
Option 1: Install via apt (default Ubuntu repository)
Update the system first:
Install Python 3 and essential development tools:
Check the installation:
pip3 --version
This method is simple but may not provide the latest Python version.
Option 2: Install a specific version using deadsnakes PPA
For newer Python versions:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.11 python3.11-venv python3.11-dev -y
Run the new version:
This is ideal if you need a specific Python version for compatibility.
Option 3: Install via pyenv (manage multiple Python versions)
Pyenv allows easy switching between Python versions. Install dependencies:
Install pyenv:
Add pyenv to your shell (~/.bashrc or ~/.zshrc):
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
Install a Python version:
pyenv global 3.12.1
Verify:
Pyenv is perfect for developers working on multiple projects with different Python versions.
Option 4: Build Python from source
For maximum control over features and optimizations:
wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz
tar -xf Python-3.12.1.tgz
cd Python-3.12.1
./configure --enable-optimizations
make -j$(nproc)
sudo make altinstall
Use python3.12 to run it without replacing the system default Python.
Virtual environments
To isolate project dependencies:
source myenv/bin/activate
pip install requests
deactivate
Cheat Sheet
- python3 --version — check installed Python version
- pip3 --version — check pip version
- python3 — start interpreter
- pip3 install <package> — install package
- python3 -m venv <env> — create virtual environment
- source <env>/bin/activate — activate environment
- deactivate — exit environment
Conclusion
Python 3 can be installed on Ubuntu 24.04 in multiple ways: via apt for simplicity, deadsnakes PPA for specific versions, pyenv for version management, or from source for maximum customization. Using virtual environments ensures isolated dependencies for smooth development.