Install Python 3 on CentOS 6.5
- 1. check python version on current Linux OS and download Python3 source code package
- 2. setup compilation、 make、make install
- 3. create a link to python 3
Existing Python Packages
You may already have Python installed on your server, you can verify using:
[rainbow@master Desktop]$ which python
/usr/bin/python
[rainbow@master Desktop]$ python --version
Python 2.6.6
[rainbow@master Desktop]$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Download Python 3
First, visited python web and download source code package that you want to use, for this example I’m downloading the latest stable version 3.4.3:
https://www.python.org/downloads/ [ download page ]
Install Python 3
Next, go to the download directory and extracted package
[rainbow@master ~]$ cd Downloads/
Python-3.4.3.tgz
[rainbow@master ~]$ tar -xvf Python-3.4.3.tgz
[rainbow@master ~]$ ls
Python-3.4.3
Python-3.4.3.tgz
then, go to the extracted Python directory:
[rainbow@master ~]$ cd Python-3.4.3
[rainbow@master Python-3.4.3]$ ls
build Include Misc python
config.guess install-sh Modules Python
config.log Lib Objects python-config
config.status libpython3.4m.a Parser python-config.py
config.sub LICENSE PC python-gdb.py
configure Mac PCbuild README
configure.ac Makefile pybuilddir.txt setup.py
Doc Makefile.pre pyconfig.h Tools
Grammar Makefile.pre.in pyconfig.h.in
Then setup compilation:
[rainbow@master Python-3.4.3]$ ./configure
Note: If you receive the error: configure: error: no acceptable C compiler found in $PATH during this step, run this command before configuring:
[rainbow@master Python-3.4.3]$ yum install gcc
Then build:
[rainbow@master Python-3.4.3]$ make
And install:
[rainbow@master Python-3.4.3]$ make install
Next, verify Python 3 installation:
[rainbow@master Python-3.4.3]$ /usr/local/bin/python3 --version
Python 3.4.3
Finally, create a link to Python 3 executable for easy usage:
[rainbow@master Python-3.4.3]$ ln -s /usr/local/bin/python3 /usr/bin/python3
And check:
[rainbow@master Python-3.4.3]$ python3 --version
Python 3.4.3
[rainbow@master Python-3.4.3]$ python3
Python 3.4.3 (default, Jun 18 2015, 16:32:03)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Now Python 3 is successfully installed and working.