How to download, compile, and install Python on Ubuntu/Debian/ CentOS Linux

Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.

Please use md5 checksum to make sure the downloaded files are not corrupt. Also, $ before commands mean you can run the command as ordinary user and # means you have to run the command as root (or use $ sudo )

 

$ wget http://www.python.org/ftp/python/2.7/Python-2.7.tgz
$ tar xzf Python-2.7.tgz
$ cd Python-2.7
$ ./configure --with-pth --with-dec-threads --with-signal-module --prefix=/opt/python-2.7
$ make
# make install

 

This should insall Python 2.7 in /opt/python-2.7. I symlinked /opt/python to /opt/python-2.7/ to make it the default Python installation on my machine.

Did this tutorial help a little? How about buy me a cup of coffee?

Buy me a coffee at ko-fi.com

Please feel free to use the comments form below if you have any questions or need more explanation on anything. I do not guarantee a response.

IMPORTANT: You must thoroughy test any instructions on a production-like test environment first before trying anything on production systems. And, make sure it is tested for security, privacy, and safety. See our terms here.

Comments (write a comment):

Thanks a ton! This really helped! Posted by: PyUser on Mar 20, 2011

Thank you! Posted by: Tracy on Feb 02, 2012

My company is looking for freelance python coders, can you suggest anyone? Posted by: Michael W on Mar 28, 2012

Thanks so much!!! This is extremely helpful Posted by: Brandon on Apr 10, 2012

This really helped. Thank you very much. Posted by: Godzillalow on Apr 17, 2012

$ make install
gcc -pthread -Xlinker -export-dynamic -o python \
Modules/python.o \
libpython2.7.a -lpthread -ldl -lutil -lm -threads
gcc: error: unrecognized option ‘-threads’
make: *** [python] Error 1


Thoughts? Posted by: Steve S on Apr 29, 2012

hello sir,
thanks for help, it's installing on ubantu 12.04, but when i giving make command it's giving error>>

root@deep-Aspire-5745:/home/deep/Python-2.7# make
gcc -pthread -Xlinker -export-dynamic -o python \
Modules/python.o \
libpython2.7.a -lpthread -ldl -lutil -lm -threads
gcc: error: unrecognized option ‘-threads’
make: *** [python] Error 1
root@deep-Aspire-5745:/home/deep/Python-2.7#

please help me Posted by: kuldeep m on May 11, 2012

I am getting following error while doing "make"

gcc -pthread -Xlinker -export-dynamic -o python \
Modules/python.o \
libpython2.7.a -lpthread -ldl -lutil -lm -threads
gcc: error: unrecognized option ‘-threads’
make: *** [python] Error 1

A quick help is highly appreciated.
I am not sure why it is needed. Posted by: piyush on Jun 12, 2012

I have quickly removed it -thread from the make file.
like
#LDLAST= -lpthreads
LDLAST=

And did make and make install.
However I am not sure what functionally I will be missing. Please help. Posted by: piyush on Jun 12, 2012

change the "Python-2.7.tgz" to "Python-3.3.0b1.tgz" Posted by: NAf on Jun 27, 2012

Thank you for sharing your knowledge Posted by: fruela on Oct 03, 2012

leave a comment on tutorial leave a comment