Home Linux Server Install Python 3 and set it as the default on Centos 7

Install Python 3 and set it as the default on Centos 7

Published: Last Updated on

The most detailed guide to installing Python 3 and setting it as the default on Centos 7 with AZDIGI.

I. Introduction

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 newbies. 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, its clarity, ease of understanding, and flexible typing make it an ideal language for scripting and application development in various fields on most platforms.

You can learn more about Python through each version and the structure and operating principles here.

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 as root, if you don’t know how to SSH, you can see the instructions below:

Step 2: Check your Python version

By default Python installed on Centos 7 will be Python 2.7.x version, you use the following command to check the version:

AZDIGI Tutorial
python --version

So now my VPS is using Python version 2.7.

Install Python 3 and set it as the default on Centos 7

So to upgrade to Python 3 version, go to step 3.

Step 3: Update the Yum management tool

AZDIGI Tutorial
yum -y update                    (Cập nhật yum)
yum -y install yum-utils         (Cài đặt yum utils)
yum -y groupinstall development  (cài đặt các công cụ phát triển CentOS giúp xây dựng và biên dịch phần mềm từ mã nguồn.)

Step 4: Install Python 3

To check and download the latest Python versions, you can visit the homepage here.

  • Since the standard yum repos don’t have the latest Python release, we will install the IUM (Inline with Upstream Stable) which will have the latest packages by running the following command:
AZDIGI Tutorial
yum install \
https://repo.ius.io/ius-release-el7.rpm \
  • Now install Python 3, I will install Python 3.6 with the command:
AZDIGI Tutorial
yum -y install python36u
Install Python 3 and set it as the default on Centos 7
As shown above, I have successfully installed Python 3.
  • Next, we will install PIP to manage software packages for Python.
AZDIGI Tutorial
yum -y install python36u-pip
  • Then we will install the Python development packages.
AZDIGI Tutorial
yum -y install python36u-devel
  • Finally, check the Python version you just installed.
AZDIGI Tutorial
python3.6 --version
Install Python 3 and set it as the default on Centos 7

Step 5: Set Python 3 as the 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, I previously installed Python 3.6 version, so I will use the following command:
AZDIGI Tutorial
which python3.6

The path will display as follows:

[root@template bin]# which python3.6
  • Add the Alias in bash_profile.

This section means that we will add an 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:

AZDIGI Tutorial
vi ~/.bash_profile  
  • Insert the following navigation into the .bash_profile file.

Remember to replace /usr/bin/python3.6 with the path on your VPS.

AZDIGI Tutorial
alias python='/usr/bin/python3.6'
Install Python 3 and set it as the default on Centos 7

After editing, type :x to Save the configuration.

  • Reload .bash_profile
AZDIGI Tutorial
source ~/.bash_profile
  • Recheck the Python version .
AZDIGI Tutorial
python --version
Install Python 3 and set it as the default on Centos 7
As shown above, the default version has been changed to 3.6.8.

III. Summary

So in this article, AZDIGI showed you how to install Python 3 and set this new version of Python as the system default. With this upgrade, you will be able to use many 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 it successfully!

If you find the article helpful, please share it widely.

If you need assistance, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign