• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Install Python 2.7.18 on Ubuntu & LinuxMint

Written by Rahul, Updated on July 23, 2020

This article will help you to install Python 2.7.18 on your Ubuntu, Debian and LinuxMint operating systems. At writing time of this article Python 3.4.5 latest stable version is available to download and install.

To install Python 3.4.5 visit following article.

  • How to Install Python 3.4 on Ubuntu & LinuxMint
  • Step 1 – Prerequisites

    You must have installed the following prerequisites on your system. Execute the following commands on your system to install all required dependencies to build Python 2.7.

    sudo apt-get update
    sudo apt-get install build-essential checkinstall
    sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
    

    Step 2 – Download Python 2.7

    Download Python using following command from python official site. You can also download latest version in place of specified below.

    cd /usr/src
    wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
    

    Now extract the downloaded package.

    sudo tar xzf Python-2.7.18.tgz
    

    Step 3 – Compile Python Source

    Use below set of commands to compile Python source code on your system using altinstall.

    cd Python-2.7.18
    sudo ./configure --enable-optimizations
    sudo make altinstall
    

    make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

    Step 4 – Check Python Version

    Check the latest version installed of python using below command

    python2.7 -V
    
    Python 2.7.18
    

    Share it!
    Share on Facebook
    Share on Twitter
    Share on LinkedIn
    Share on Reddit
    Share on Tumblr
    Share on Whatsapp
    Rahul
    Rahul
    Connect on Facebook Connect on Twitter

    I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

    43 Comments

    1. Avatar DAYANAND SHAHPURKAR Reply
      January 16, 2021 at 3:55 am

      Thank you very much, it worked without any issue.

    2. Avatar Matias Reply
      December 10, 2020 at 10:48 pm

      Thank you!

    3. Avatar Chelovek Reply
      July 27, 2020 at 6:13 am

      Thank you!

    4. Avatar Robert N Ackerman Reply
      July 12, 2020 at 1:40 pm

      Step 1 doesn’t work for Linux Mint 20.
      [email protected]:~$ sudo apt-get install build-essential checkinstall
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      You might want to run ‘apt –fix-broken install’ to correct these.
      The following packages have unmet dependencies:
      build-essential : Depends: libc6-dev but it is not going to be installed or
      libc-dev
      Depends: g++ (>= 4:9.2) but it is not going to be installed
      python-gtk2 : Depends: python (= 2.7)
      Depends: python-numpy (>= 1:1.13.1) but it is not going to be installed
      Depends: python-numpy-abi9
      Depends: python:any (>= 2.6.6-7~)
      E: Unmet dependencies. Try ‘apt –fix-broken install’ with no packages (or specify a solution).
      [email protected]:~$

      Being a beginner at this, I have no idea how to proceed.

    5. Avatar PK Reply
      May 28, 2020 at 6:54 am

      Hey, you have wrong url, should be https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz

      • Rahul Rahul Reply
        May 28, 2020 at 12:44 pm

        Thanks, I have updated the URL.

    6. Avatar nardinez Reply
      January 6, 2020 at 5:54 pm

      Works great thanks! but how then to install new packages and liberaries with pip install?

    7. Avatar Sandro Reply
      December 18, 2019 at 1:27 am

      Thank you!

    8. Avatar Gustavo Reply
      October 15, 2019 at 9:49 am

      Thanks a lot Rahul.

    9. Avatar Sergio Reply
      September 30, 2019 at 9:01 pm

      Thanks RAHUL.

    10. Avatar Maxwell Reply
      August 15, 2019 at 1:13 am

      Thank you a lot!

    11. Avatar Md Asaduzzaman Reply
      June 5, 2019 at 3:06 pm

      Thanks,
      nicely install but it’s ,python2.7.16 not the default. default one is 3.6.8. How I can make default python2.7.16 . Please let me know.

      • Rahul Rahul Reply
        June 6, 2019 at 4:49 am

        Hi, I will not suggest you change the default Python version. Changing the default Python may break the working of many application or entire operating system.

    12. Avatar Guy Reply
      April 15, 2019 at 12:11 pm

      Worked like a treat.
      In my case, the default python version for Ubunu got rekt, so apt could not function. I followed your process and used install instead of altinstall, because I needed to replace a broken 2.7.x default. Saved me re-installing Ubuntu

    13. Avatar walidking Reply
      March 30, 2019 at 11:02 pm

      You’re the man!!

    14. Avatar Bruna Reply
      March 23, 2019 at 6:27 pm

      Thanks a lot!

    15. Avatar Burak Reply
      October 7, 2018 at 4:41 pm

      I have compleated all steps but it still shows 2.7.6 ?

    16. Avatar Christophe Reply
      August 26, 2018 at 7:57 am

      Thanks a lot, It really helped me!

    17. Avatar Dipali Reply
      July 12, 2018 at 9:38 am

      Hello sir, Thank u for such great tutorial…
      It helped me alot.
      Once again thank you 🙂

      • Avatar Victor Morgan Reply
        July 23, 2020 at 11:18 am

        In step 2 I tried Downloading Python using the following command from python official site but i get HTTP request sent, awaiting response…404 Not found

    18. Avatar dabrain34 Reply
      May 16, 2018 at 9:26 am

      Please consider that many patches are applied, and one important is the platform.py allowing to detect the ubuntu release version.

      https://packages.ubuntu.com/xenial/python2.7

      You can see a set of diff on the right side, named [python2.7_2.7.12-1ubuntu0~16.04.2.diff.gz]

    19. Avatar MANOHAR ROYAL Reply
      April 19, 2018 at 2:54 am

      Very Clear…Great one!!!

    20. Avatar atom Reply
      April 13, 2018 at 6:54 am

      excuse me for wondering that how to cleanly remove them after installing because “make uninstall* seems not available

    21. Avatar Vicente Reply
      March 15, 2018 at 3:20 pm

      Thank you!

    22. Avatar Mark Reply
      January 15, 2018 at 10:17 pm

      very straightforward setup for Windows Ubuntu Subsystem! Cheers!

    23. Avatar Niikola Andrii Reply
      December 17, 2017 at 3:15 am

      Clean, sharp instructions, thanks kid 🙂

    24. Avatar ayatollah1988 Reply
      November 29, 2017 at 4:34 am

      Awesome, you’re a lifesaver. They have python 2.14 now so if you just replace all the commands that have “2.7.13” with “2.7.14” it works fine

    25. Avatar Amitav Reply
      November 18, 2017 at 3:51 pm

      Thanks Rahul

    26. Avatar Russel F. Reply
      November 17, 2017 at 7:30 pm

      Thanx, this worked – Got Python 2.7.14 working on an older Linux version, which runs on a laptop. Looks nice, but of course, no pip, and no image library. Working on getting these… But again, thanx. Previous Python version was 2.5, and now at least I have 2.7.14, from http://www.python.org, compiled from source, which was my objective. FYI: THe source download was in a .tar.xz form, and I did not have the xz-utils on my Linux version. I had to scp the python-2.7.14.tar.xz file over to a current CentOS box, run the “unxz” utility to decompress the 12 mb file into a 71 mb file, and scp it back to the laptop, where I could then do the ./configure, make and make install (I wanted to overwrite the old Python version). Looks like it all worked. Trick now is to get the image stuff and pip, which should be somewhere… (if it exists, it has to be somewhere, no?) 😉

    27. Avatar madethisformrrobot Reply
      November 7, 2017 at 3:26 am

      This was very helpful. I’m new to python and this worked on the first try.

    28. Avatar Uhulum Reply
      October 29, 2017 at 7:22 pm

      This fails when I get to step “wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz“.
      This is what I get:
      –2017-10-29 20:20:38– https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
      Resolving http://www.python.org (www.python.org)… 151.101.84.223, 2a04:4e42:14::223
      Connecting to http://www.python.org (www.python.org)|151.101.84.223|:443… connected.
      HTTP request sent, awaiting response… 200 OK
      Length: 17076672 (16M) [application/octet-stream]
      Python-2.7.13.tgz: Permission denied

      • Rahul Rahul K. Reply
        October 30, 2017 at 10:25 am

        Hi, It looks you are facing issue with downloading file under /usr/src directory. Kindly switch to superuser to run commands or use sudo. I have updated the tutorial with sudo commands.

        • Avatar suvidha chaudhari Reply
          April 14, 2018 at 6:10 pm

          hello sir , i followed d your above step in my system. but when i type a command python -V in terminal its display older version(2.7.6).

          • Avatar JLord Reply
            October 12, 2018 at 11:48 pm

            equals, version wasn’t replace

    29. Avatar David Reply
      October 20, 2017 at 9:39 pm

      Thanks dude, this worked a treat!

    30. Avatar David Reply
      August 1, 2017 at 4:33 am

      I followed instructions on Linux Mint Cinnamon 17.3 and ended up with latest python, but missing crucial modules like datetime and time.

    31. Avatar Fayaz Reply
      July 12, 2017 at 6:42 am

      Thanks for the article.

    32. Avatar Pele Reply
      July 9, 2017 at 2:40 pm

      i would suggest running sudo apt-get update
      before running the first two commands

    33. Avatar Roumen Reply
      May 18, 2017 at 9:32 pm

      If you are on Linux you will most likely need to add
      –enable-unicode=ucs4
      to the arguments of ./configure to keep it consistent with the ‘standard’ builds.

    34. Avatar Don Reply
      May 9, 2017 at 4:31 am

      I get
      E: Unable to locate package checkinstall

    35. Avatar mAYBe Reply
      February 8, 2017 at 5:53 am

      Thank you…. great!!

    36. Avatar Aldi Unanto Reply
      July 31, 2015 at 2:07 am

      Thank you so much!

      • Avatar Brad Reply
        November 22, 2015 at 3:10 pm

        Great this was very helpful. One issues i found. I believe you need to run a: ‘sudo make’ command and allow that to run before you run the sudo make altinstall command.
        Otherwise worked perfectly for me.

    Leave a Reply Cancel reply

    Popular Posts

    • How To Install Python 3.9 on Ubuntu 20.04 5
    • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
    • How To Install VNC Server on Ubuntu 20.04 1
    • How To Install NVM on macOS with Homebrew 0
    • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
    © 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy