The most common method to install Python on Linux is via the distribution's package manager, which automatically handles dependencies and system integration. For Ubuntu/Debian/Mint, run sudo apt update followed by sudo apt install python3 python3-pip. For Fedora/RHEL/CentOS, use sudo dnf install python3 python3-pip (or yum on older versions). For Arch Linux, execute sudo pacman -S python python-pip.
Important considerations include:
Version Locking: On Debian-based systems, the major Python version is often locked to the OS release; to get a newer version, you must upgrade the OS, use a third-party repository (like the deadsnakes PPA on Ubuntu), or install pyenv.
pip Installation: While often included,
pipcan be explicitly installed viasudo apt install python3-pip(Debian/Ubuntu) orsudo dnf install python3-pip(Fedora/CentOS).Compilation: Compiling from source code is an advanced option recommended only for specific cases where a version not available in repositories is required.
Virtual Environments: To avoid breaking system tools, it is recommended to use virtual environments (
python3 -m venv) for project-specific dependencies.
| Distribution | Package Manager | Installation Command |
| Ubuntu/Debian/Mint | apt | sudo apt install python3 python3-pip |
| Fedora/RHEL/CentOS | dnf / yum | sudo dnf install python3 python3-pip |
| Arch Linux | pacman | sudo pacman -S python python-pip |
| Amazon Linux | yum | sudo yum install python3 |
Installing python on Linux - help?
Getting started with Python development on a linux-system
How do I install python 2.7
How does one install Python 3.7 in HPC without root access on Linux?
Videos
I am a long-time user of Python but I have never understood how to install python "properly" - I tend to figure out some way to get it done when I need to, and then forget all about it. But I want to understand it a bit better because it isn't straightforward in my opinion. I am not considering Pyenv or other such "helper" tools/dependencies - I want to learn how to do this the "official" way. I've looked at the official docs but can't see what I've done incorrectly. The main issue is that at some stage I often find myself wanting a newer version of python than what is provided, and then I end up a bit stuck.
I installed Debian and it came with python3 under my /usr/local/bin directory. There is also a Python installation under /usr/bin/python3.11, which I guess is my system python? I believe I was always interacting with my /usr/local/bin python - not the system python, so that's good. (Also I'm always using virtual environments, so let's not discuss their importance please). That was working fine for me, but now I want to upgrade my version of python and I am facing difficulties.
-
What should I do to upgrade python in an "official" way (i.e. not adding dev repositories like deadsnakes, not using helper tools like Pyenv)?
-
What do I need to do with pip? Currently, the pip command actually points to
/usr/bin/python- i have to use pip3* (see below). -
Can I simply delete the old python and pip versions from
/usr/local/binif I wanted to? -
How do I ensure that every time I type
python3in the terminal, it grabs the latest one? Do I just ensure it is higher up in my PATH variable? -
Why is there not one simple way to do this? Obviously everyone has slightly different needs, but I imagine 80% of python users just want to use python and have a reasonable way to upgrade when required without screwing something up in their system.
To explain why I'm asking this now, I installed the python source from the main website yesterday and tried to get it working but something is off. Here's what I did
-
Extracted the Python-3.12.3.tar.xz
-
Moved into the dir and ran
./configure --enable-optimizations --with-ensurepip=install -
Ran
make -
Ran
sudo make install
This worked, but I notice when I run python in the terminal REPL that I can't use the up/down keys to cycle through my command history:
>>> print("hello")
hello
>>> ^[[A*Also, I notice that I now have pip (/usr/bin/python), pip3, and pip3.12 now, and I am confused about that. Should I alias pip with pip3.12 to prevent interacting with the system python? Should I just delete pip3 and make sure pip3 points to pip3.12?
These issues have convinced me that I've now installed python incorrectly somehow. I found some info about readline but that's deprecated, and I am starting to go down the rabbit hole of running random commands to try and fix things, which is probably going to make things worse.