CentOS 7 ships with 2.7.5 and that's not the best when you're wanting to use Python 3.x so I'm going to teach you how to install 3.x.
This will work for any python version so you don't have to use 3.7.5 like I did here. You can go and use the latest instead.
python -Vand see what it says. If it's not 3.x then continue to step 2.
whereis python, if you don't see any python3.x binaries then continue to step 3.
- Run as root/sudo
yum groupinstall -y "Development Tools"then run
yum install gcc openssl-devel bzip2-devel libffi-devel -y
- Jump on over to the Python download page and find the link for the Gzipped source tarball. For this guide we're going to be installing 3.7.5.
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgzor upload the source to the machine.
- Once the source is on the machine then run
tar -xvzf Python-3.7.5.tgz.
cd Python-3.7.5/and then run
- Now that you've configured the build for Python you can build and install it by doing
make altinstall. This process will take some time so let it run. You don't want to do
make install, because this will mess with Python 2 which is required by most of the components of CentOS 7.
- Python 3.x should be installed now so now you can do
python3.x -V(in this guide should be
Upgrading from 3.7.5 to 3.7.6 or another version will be the same as above, but you'll go and delete the previous version before you start.
whereis python and then you'll delete the previous verison files.
rm -rf /usr/local/lib/python3.7 rm -rf /usr/local/bin/python3.7m rm -rf /usr/local/bin/python3.7 rm -rf /usr/local/bin/python3.7m-config
Note: If you're going to be using sqlite or any database then you need to install it also and the devel package. For example (sqlite-devel mariadb mariadb-server mariadb-devel).
until next time