Python installation
Arch Linux
Python 3.8
Python 3.9
Linux tutorial

How to install Python 3.8 along with Python 3.9 in Arch Linux?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Arch Linux ships the latest Python version in its official repositories, but many projects require older versions like Python 3.8 alongside the system Python. The recommended approach is to use pyenv, which compiles and manages multiple Python versions in your home directory without affecting system packages. Alternatives include installing from the AUR (Arch User Repository) or building from source. Each method has trade-offs in convenience, maintenance, and system integration.

bash
1# Install pyenv and its dependencies
2sudo pacman -S --needed base-devel openssl zlib xz tk
3
4# Install pyenv via the official installer
5curl https://pyenv.run | bash
6
7# Add to ~/.bashrc or ~/.zshrc
8echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
9echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
10echo 'eval "$(pyenv init -)"' >> ~/.bashrc
11source ~/.bashrc
12
13# List available Python versions
14pyenv install --list | grep 3.8
15
16# Install Python 3.8 and 3.9
17pyenv install 3.8.19
18pyenv install 3.9.19
19
20# Verify installations
21pyenv versions
22#   system
23#   3.8.19
24#   3.9.19

pyenv compiles Python from source in ~/.pyenv/versions/. It does not touch the system Python and allows switching between versions per project or globally.

Setting Active Python Versions

bash
1# Set global default
2pyenv global 3.9.19
3
4# Set Python version for a specific project directory
5cd ~/my-project
6pyenv local 3.8.19
7# Creates a .python-version file in the directory
8
9# Verify
10python --version  # Python 3.8.19
11
12# Temporarily use a specific version
13pyenv shell 3.8.19
14python --version  # Python 3.8.19
15
16# Make multiple versions available simultaneously
17pyenv global 3.9.19 3.8.19
18python3.9 --version  # Python 3.9.19
19python3.8 --version  # Python 3.8.19

pyenv local creates a .python-version file that automatically activates when you cd into the directory. pyenv global sets the default for your user. pyenv shell overrides for the current terminal session.

Method 2: AUR Package

bash
1# Install an AUR helper if you don't have one
2sudo pacman -S --needed git base-devel
3git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si
4
5# Search for Python 3.8 in the AUR
6yay -Ss python38
7
8# Install Python 3.8 from AUR
9yay -S python38
10
11# After installation
12python3.8 --version  # Python 3.8.x
13python3 --version    # System Python (3.9+)
14
15# Create a virtual environment with Python 3.8
16python3.8 -m venv myenv
17source myenv/bin/activate
18python --version  # Python 3.8.x

AUR packages install Python system-wide alongside the official Python. The binary is accessible as python3.8, keeping python3 pointing to the system version.

Method 3: Build from Source

bash
1# Install build dependencies
2sudo pacman -S --needed base-devel openssl zlib xz tk sqlite
3
4# Download and extract Python 3.8 source
5cd /tmp
6wget https://www.python.org/ftp/python/3.8.19/Python-3.8.19.tgz
7tar xzf Python-3.8.19.tgz
8cd Python-3.8.19
9
10# Configure with altinstall prefix to avoid overwriting system Python
11./configure --prefix=/usr/local --enable-optimizations
12
13# Build with all CPU cores
14make -j$(nproc)
15
16# Install as altinstall (installs as python3.8, not python3)
17sudo make altinstall
18
19# Verify
20python3.8 --version  # Python 3.8.19
21python3 --version    # System Python (unchanged)

make altinstall is critical — it installs as python3.8 and pip3.8 without creating python3 or pip3 symlinks that would overwrite the system Python.

Creating Virtual Environments

bash
1# With pyenv
2pyenv shell 3.8.19
3python -m venv myproject-env
4source myproject-env/bin/activate
5
6# With system-installed python3.8
7python3.8 -m venv myproject-env
8source myproject-env/bin/activate
9
10# Verify the environment uses the correct Python
11python --version  # Python 3.8.x
12which python      # /path/to/myproject-env/bin/python
13
14# Install packages in the isolated environment
15pip install numpy pandas

Virtual environments isolate project dependencies regardless of which Python installation method you use. Always use virtual environments for project development.

Using pyenv with pyenv-virtualenv

bash
1# Install pyenv-virtualenv plugin
2git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
3echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
4source ~/.bashrc
5
6# Create a virtualenv with a specific Python version
7pyenv virtualenv 3.8.19 myproject-3.8
8
9# Activate it
10pyenv activate myproject-3.8
11
12# Or set it for a directory
13cd ~/my-project
14pyenv local myproject-3.8
15# Automatically activates when you enter the directory
16
17# List all virtualenvs
18pyenv virtualenvs
19
20# Delete a virtualenv
21pyenv uninstall myproject-3.8

pyenv-virtualenv combines Python version management with virtual environments, giving you named environments tied to specific Python versions.

Common Pitfalls

  • Using make install instead of make altinstall: make install overwrites the system python3 symlink, breaking system tools that depend on the Arch-provided Python. Always use make altinstall when building from source.
  • Missing build dependencies: Python's configure script silently skips optional modules (like _ssl, _sqlite3, _lzma) if their development headers are missing. Install openssl, zlib, xz, tk, and sqlite before building.
  • AUR packages breaking on system updates: When Arch updates its system Python or shared libraries, AUR Python packages may need rebuilding. Run yay -S python38 again after major system updates if the binary stops working.
  • pyenv not updating PATH correctly: If python --version still shows the system Python after pyenv global, ensure eval "$(pyenv init -)" is in your shell config and the shell was restarted. pyenv works by prepending shims to your PATH.
  • Conflicting pip installations: Running pip install without a virtual environment installs packages into the active Python's site-packages. This can cause version conflicts between Python 3.8 and 3.9. Always work inside virtual environments.

Summary

  • Use pyenv for the cleanest multi-version Python setup on Arch Linux
  • Use AUR packages (yay -S python38) for system-wide installation without building from source
  • Use make altinstall (not make install) when building from source to avoid overwriting system Python
  • Always create virtual environments for project isolation regardless of installation method
  • pyenv local creates per-directory Python version switching via .python-version files
  • Install all build dependencies before compiling Python to avoid missing modules

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.