How to install Python 3 and set defaults on Centos 7
What is Python?
Python is a powerful, high-level, object-oriented programming language, created by Guido van Rossum. It’s easy to learn and is emerging as one of the best introductory programming languages for first-timers. Python is completely dynamically typed and uses automatic memory allocation. Python has powerful high-level data structures and a simple yet effective approach to object-oriented programming. Python’s command syntax is a huge plus as its clarity, ease of understanding, and flexible typing make it rapidly becoming an ideal language for scripting and application development in a wide variety of fields, in most areas. all platforms.
You can learn more about Python through each version as well as the structure and operating principles .
II. Implementation Guide
To install Python 3 you can follow the following 3 installation steps.
Step 1: SSH into your VPS
First you need to SSH into your VPS with Root rights.
Step 2: Check the version of Python you are using
By default Python installed on Centos 7 will be Python 2.7.x version, you use the following command to check the version.
So currently this VPS of mine is using Python version 2.7.
So to upgrade to Python 3 version, you continue to step 3.
Step 3: Update the Yum . management tool
yum -y update (Update yum) yum -y install yum-utils (Install yum utils) yum -y groupinstall development (installs CentOS development tools that help build and compile software from source code.)
Step 4: Install Python 3
To check and download the latest Python versions, you can visit the homepage
- Since the standard yum repos don’t have the latest python release, we will install the IUS (Inline with Upstream Stable) which will have the latest packages. You run the command.
yum install \ https://repo.ius.io/ius-release-el7.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- Now install Python 3, here I will install Python 3.6 with the command.
yum -y install python36u
- Next, we will install PIP , which will manage software packages for Python.
yum -y install python36u-pip
- Finally, we will install the Python development packages
yum -y install python36u-devel
- Check the installed Python version
Step 5: Set Python 3 as Default
Although we have successfully installed Python 3, the VPS will still use Python version 2.7.5 as default. To change the default version, do the following.
- Check the location where Python 3 has just been installed, before that I installed Python 3.6 version, so I will use the following command.
The path will display as follows
which python3.6 /usr/bin/python3.6
- Write alias in bash_profile.
This part means that we will add Alias configuration so that when calling the python command, the system will load the specified path (here is Python version 3.6). You open and edit the bash_profile file with the command.
- Insert the following navigation into the .bash_profile file .
Remember to replace /usr/bin/python3.6 with the path on your VPS.
alias python = '/usr/bin/python3.6'
After editing, tap
:wqto Save the configuration.
- Reload .bash_profile with command
- Check the Python version again .
Thus, in this article, We showed you how to install Python 3 and at the same time showed you how to set this new version of Python as the system default. With this upgrade, you will be able to use more new Packages from Python because each new Package is developed they have conditions attached to the supported version. Hope this article will help you to install successfully.!