CentOS 6.x system upgrades Python to 2.7 version of Shell script sharing _linux Shell

Source: Internet
Author: User
Tags install openssl

On CentOS 6.x, the default Python is the 2.6.x version, and this version of Python is a bit old, like "collections." Ordereddict "is only 2.7, and the famous Python web framework Django new version (such as: 1.7) does not support Python2.6, the minimum requirement is 2.7." And some companies or shared cloud servers are using centos6.x, so there's a need to upgrade Python to 2.7.

Before you upgrade Python, you need to install some tools and software libraries, otherwise you may have an error installing Python or pip later.
Python2.7 through the source installation, Python executable program is installed by default in/usr/local/bin/, generally in $path,/usr/local/bin is preferred (if not, you need to set up the PATH environment variable).
After you install Python, you will also need to install the two most common tools for Easy_install and Pip.

Throughout the installation process, I have summarized the following shell script (to install Python2.7.8 as an example, run as root) for reference:

https://github.com/smilejay/shell/blob/master/sh2014/install_py27_on_centos.sh

Copy Code code as follows:

#!/bin/bash
# a script to install Python 2.7 on CentOS 6.x system.
# CentOS 6.x has Python 2.6 by default while some software (e.g. django1.7)
# need Python 2.7.

# Install some necessary tools & Libs
echo "Install some necessary tools & Libs"
Yum Groupinstall "Development Tools"
Yum install openssl-devel zlib-devel ncurses-devel bzip2-devel
Yum install libtool-ltdl-devel sqlite-devel tk-devel tcl-devel
Sleep 5

# Download and install Python
version= ' 2.7.8 '
Python_url= "https://www.python.org/ftp/python/$version/python-${version}.tgz"

# Check Current Python version
echo "Before installation, your Python version is: $ (python-v &2>1)"
Python-v 2>&1 | grep "$version"
If [$?-eq 0]; Then
echo "Current version are the same as this installation."
echo "Quit as no need to install."
Exit 0
Fi

echo "Download/build/install your Python"
Cd/tmp
wget $python _url
TAR-ZXF python-${version}.tgz
CD Python-${version}
./configure
Make-j 4
Make install
Sleep 5

echo "Check your installed Python"
Python-v 2>&1 | grep "$version"
If [$?-ne 0]; Then
echo "Python-v is not your installed version"
/usr/local/bin/python-v 2>&1 | grep "$version"
If [$?-ne 0]; Then
echo "Installation failed. Use '/usr/local/bin/python-v ' to have a check '
Fi
Exit 1
Fi
Sleep 5

# Install Setuptools
echo "Install Setuptools"
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
Python ez_setup.py
# Check Easy_install version
Easy_install--version
Sleep 5

# Install PIP for the new Python
echo "Install Pip for the new Python"
Easy_install pip
# check PIP version
Pip-v

echo "finished. OK done! "
echo "If ' python-v ' still shows the old version, and you'll need to Re-login."
echo "and/or Set/usr/local/bin in the front of your PATH environment variable."
echo "-------------------------"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.