I have written a quick guide on how to install the latest versions of Python 2 and Python 3 on CentOS 6 and CentOS 7. It currently covers Python 2.7.13 and Python 3.6.0:

# Start by making sure your system is up-to-date:
yum update
# Compilers and related tools:
yum groupinstall -y "development tools"
# Libraries needed during compilation to enable all features of Python:
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
# If you are on a clean "minimal" install of CentOS you also need the wget tool:
yum install -y wget

The next steps depend on the version of Python you're installing.

For Python 2.7.14:

wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
tar xf Python-2.7.14.tar.xz
cd Python-2.7.14
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

# Strip the Python 2.7 binary:
strip /usr/local/lib/libpython2.7.so.1.0

For Python 3.6.3:

wget http://python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar xf Python-3.6.3.tar.xz
cd Python-3.6.3
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

# Strip the Python 3.6 binary:
strip /usr/local/lib/libpython3.6m.so.1.0

To install Pip:

# First get the script:
wget https://bootstrap.pypa.io/get-pip.py

# Then execute it using Python 2.7 and/or Python 3.6:
python2.7 get-pip.py
python3.6 get-pip.py

# With pip installed you can now do things like this:
pip2.7 install [packagename]
pip2.7 install --upgrade [packagename]
pip2.7 uninstall [packagename]

You are not supposed to change the system version of Python because it will break the system (as you found out). Installing other versions works fine as long as you leave the original system version alone. This can be accomplished by using a custom prefix (for example /usr/local) when running configure, and using make altinstall (instead of the normal make install) when installing your build of Python.

Having multiple versions of Python available is usually not a big problem as long as you remember to type the full name including the version number (for example "python2.7" or "pip2.7"). If you do all your Python work from a virtualenv the versioning is handled for you, so make sure you install and use virtualenv!

Answer from Daniel Eriksson on Stack Overflow
Top answer
1 of 10
147

I have written a quick guide on how to install the latest versions of Python 2 and Python 3 on CentOS 6 and CentOS 7. It currently covers Python 2.7.13 and Python 3.6.0:

# Start by making sure your system is up-to-date:
yum update
# Compilers and related tools:
yum groupinstall -y "development tools"
# Libraries needed during compilation to enable all features of Python:
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
# If you are on a clean "minimal" install of CentOS you also need the wget tool:
yum install -y wget

The next steps depend on the version of Python you're installing.

For Python 2.7.14:

wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
tar xf Python-2.7.14.tar.xz
cd Python-2.7.14
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

# Strip the Python 2.7 binary:
strip /usr/local/lib/libpython2.7.so.1.0

For Python 3.6.3:

wget http://python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar xf Python-3.6.3.tar.xz
cd Python-3.6.3
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

# Strip the Python 3.6 binary:
strip /usr/local/lib/libpython3.6m.so.1.0

To install Pip:

# First get the script:
wget https://bootstrap.pypa.io/get-pip.py

# Then execute it using Python 2.7 and/or Python 3.6:
python2.7 get-pip.py
python3.6 get-pip.py

# With pip installed you can now do things like this:
pip2.7 install [packagename]
pip2.7 install --upgrade [packagename]
pip2.7 uninstall [packagename]

You are not supposed to change the system version of Python because it will break the system (as you found out). Installing other versions works fine as long as you leave the original system version alone. This can be accomplished by using a custom prefix (for example /usr/local) when running configure, and using make altinstall (instead of the normal make install) when installing your build of Python.

Having multiple versions of Python available is usually not a big problem as long as you remember to type the full name including the version number (for example "python2.7" or "pip2.7"). If you do all your Python work from a virtualenv the versioning is handled for you, so make sure you install and use virtualenv!

2 of 10
14
vim `which yum`
modify #/usr/bin/python to #/usr/bin/python2.4
🌐
IBM
community.ibm.com › community › user › discussion › python3-specific-version-installation
Python3 specific version installation | Open Source Development
June 14, 2021 - Hi,Is there any way to install specific version of python3 using yum.Last time when I ran yum install python3 command in AIX it installed 3.7.9 version in devel
🌐
Serverspace
serverspace.io › support › help › install-python-centos
How to Install or Upgrade Python on CentOS 7/8 Stream: Build the Latest Python from Source
February 16, 2026 - Learn how to install or upgrade Python on CentOS 7 and CentOS 8 Stream. Step-by-step guide to building the latest Python version from source, installing dependencies, and safely updating Python on a server.
🌐
Liquid Web
liquidweb.com › home › how to install python 3 on centos 7
Install Python 3 on CentOS 7: Easy Steps for Linux Users | Liquid Web
April 7, 2025 - [root@centos7 ~]# yum update -y · Now that the environment is up to date, all we need do to install Python 3 is run the following command. [root@centos7 ~]# yum install -y python3 · That’s it! Python 3 is now installed!
🌐
DedicatedCore
dedicatedcore.com › home › how to install latest version of python 3.10 on centos 7
How to Install Latest Version of Python 3.10 on CentOS 7 - DedicatedCore Blog
May 29, 2025 - sudo yum update -y · sudo yum install -y python3 · Hold off until the installation is finished. It should be clear from the output that Python 3 and all necessary dependencies have been installed. python3 --version · You should now be able ...
🌐
DevOpsSchool.com
devopsschool.com › blog › installing-python-3-on-linux-centos-ubuntu-windows
Python Tutorials: Installing Python 3 on Linux, Centos, Ubuntu & Windows
sudo yum -y install wget make gcc openssl-devel bzip2-devel cd /tmp/ wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz tar xzf Python-3.9.1.tgz cd Python-3.9.1 ./configure --enable-optimizations sudo make altinstall sudo ln -sfn /usr/local/bin/python3.9 /usr/bin/python3.9 sudo ln -sfn /usr/local/bin/pip3.9 /usr/bin/pip3.9 python3.9 -V pip3.9 -V $ sudo ln -fs /usr/local/bin/python3.9 /usr/bin/python $ sudo ln -fs /usr/local/bin/python3.9 /usr/bin/python3Code language: JavaScript (javascript) yum update yum install openssl-devel bzip2-devel libffi-devel yum groupinstall “Development Tools” wget https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz tar -xzf Python-3.10.2.tgz cd Python-3.10.2 ./configure –enable-optimizations make altinstall python3.10 -V
🌐
Linux Stans
linuxstans.com › how-to-install-python-centos
How to Install Python 3.10 (or 3.11) on CentOS - Linux Stans
January 24, 2022 - To install it, just run yum install python39 and that’s it. If you want to install Python 3.10 or 3.11, follow the tutorial below. Now, onto our tutorial on how to install Python 3.10 on CentOS (any version) The first step, as always, is to ...
Find elsewhere
🌐
AlexHost
alexhost.com › home › faq › comprehensive guide to installing python 3 on centos 7
Comprehensive Guide to Installing Python 3 on CentOS 7
October 7, 2024 - sudo yum install -y python3 · “` This command installs Python 3.6 along with `pip3`, the package manager for Python. If you require a newer version, such as Python 3.9, utilize Software Collections (SCL): “`bash · sudo yum install -y ...
🌐
Medium
medium.com › @mrx04programmer › installing-any-updated-version-of-python-on-centos-7-8-or-arch-linux-563cabc8bb3c
Install any updated version python on centOS 7/8 | by mrx04programmer | Medium
August 16, 2023 - sudo yum -y update sudo yum -y install epel-release sudo yum -y groupinstall "Development Tools" sudo yum -y install openssl-devel bzip2-devel libffi-devel xz-devel sudo yum -y install wget
🌐
Reddit
reddit.com › r/almalinux › dnf/yum not working after updating python3
r/AlmaLinux on Reddit: DNF/YUM not working after updating Python3
January 10, 2023 -

Hi,

trying to find a solution for hours by now, wonder why this isnt more widespread problem.

So. I have Alma 8.5, with default python3.6 . In order for netbox to work I've installed higher Python 3.9.9 (it was last year). Cant remember how exactly but I also created i guess alternative:

/usr/bin/python3 -> /usr/local/bin/python3.9

Worked fine as I only needed this machine for netbox. Now I need to update postgresql 10 to 13, and i get this error when any command related to dnf like dnf update:

problem the operation would result in removing the following protected packages dnf yum

What i gathered is, that DNF/YUM dont work with python other than default 3.6.

How can I make DNF work again, without DNF/YUM command as it doesnt work entirely.

🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to install latest version of python 3 on centos 7
How to Install Latest Version Of Python 3 on CentOS 7
November 10, 2022 - If you are using a CentOS release older than 7.7, you need to add IUS, a yum repository that provides newer software versions and includes Python 3. ... Wait for the installation to complete. Then, update the repository: ... Note: Not sure which CentOS release you are running? There are many different ways to check the CentOS version. 3. Install Python 3 by running the following command in the terminal window: ... Wait for the installation to complete. The output should display it has installed python3 and the required dependencies.
🌐
Oracle Linux
yum.oracle.com › oracle-linux-python.html
Python for Oracle Linux | Oracle, Software. Hardware. Complete.
To install Python 3 from the Oracle Linux 7 latest repository: $ sudo yum install -y python3
🌐
nixCraft
cyberciti.biz › nixcraft › howto › package management › rhel 8 install python 3 or python 2 using yum
RHEL 8 install Python 3 or Python 2 using yum - nixCraft
May 23, 2024 - Type the following yum command to install Python 3 on Red Hat Enterprise Linux version 8: sudo yum install python3 OR sudo yum module install python36 Verify installation by typing the type command/command command: $ type -a python3 python3 ...
🌐
Unihost
unihost.com › help › how to install python 3
How to Install Python 3 - Unihost.FAQ
February 23, 2023 - Before you begin, refresh the package listings. This helps ensure that yum is up to date.
🌐
Server Fault
serverfault.com › questions › 978812 › how-to-install-python3-using-yum-epel-release-on-centos7
linux - how-to install python3 using yum/epel-release on centos7 - Server Fault
# yum install python36 Failed to set locale, defaulting to C Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.copahost.com * epel: epel.besthosting.ua * extras: centos.intergenia.de * updates: ftp.halifax.rwth-aachen.de No package python36 available.
🌐
MonoVM
monovm.com › blog › centos › how to install python 3 on centos 7?
How to Install Python 3 on CentOS 7?
January 15, 2024 - Follow these steps to Yum install Python 3.8 CentOS 7: 1- Update Package Repository: Ensure your system has the latest information about available packages. ... 2- Install Python 3: Use the following command to Install Python 3.6 CentOS 7, the package is named `python3`...
🌐
Server Fault
serverfault.com › questions › 1159647 › yum-update-package-awscli-requries-python3
amazon ec2 - Yum update package awscli requries python3 - Server Fault
May 20, 2024 - Error: Problem: package awscli-1.23.10-3.el9.noarch from @System requires python3.9dist(botocore) = 1.25.10, but none of the providers can be installed - cannot install both python3-botocore-1.31.62-1.el9.noarch from appstream and python3-botocore-1.25.10-1.el9.noarch from @System - cannot install both python3-botocore-1.31.62-1.el9.noarch from appstream and python3-botocore-1.25.10-1.el9.noarch from epel - cannot install the best update candidate for package python3-botocore-1.25.10-1.el9.noarch - cannot install the best update candidate for package awscli-1.23.10-3.el9.noarch (try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages) (XID n4qjt3) “/usr/bin/yum” reported error code “1” when it ended:
🌐
Caasify
caasify.com › home › blog › how to update python version: the complete guide for 2025
How to Update Python Version: The Complete Guide for 2025 | Caasify
December 8, 2025 - Open your terminal. Update your package list by running the following command: sudo apt-get update · This ensures that you are getting the latest version of Python available from the repositories.
🌐
Spiceworks
community.spiceworks.com › software & applications
While trying to upgrade Python3 on my RHEL Linux VM I broke YUM: /usr/bin/python - Software & Applications - Spiceworks Community
July 8, 2022 - I shouldn’t have even tried to upgrade Python3, but hindsight is (as always) 20/20. This is what I’m getting when I try to use YUM: [root@RHEL7 ~]# yum update -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory [root@RHEL7 ~]# yum -bash: /usr/bin/yum: ...