Python 2.7, although not the latest version of Python, is sometimes still required for legacy applications and scripts. It’s important to note that Python 2.7 reached the end of its life on January 1, 2020, which means it no longer receives updates, including security updates. However, if you have a specific need for Python 2.7, this article will guide you through the installation process on Ubuntu, Debian, and Linux Mint.
Prerequisites
Before proceeding, ensure that you have sudo privileges on your system.
Step 1: Update Your System
It’s always a good idea to update your package lists and your system to the latest versions of all packages before installing new software. Open your terminal and run the following commands:
sudo apt-get update
sudo apt-get upgrade
Step 2: Check if Python 2.7 is Already Installed
Before installing Python 2.7, check if it is already installed on your system by running:
python --version
or
python2 --version
If the output shows Python 2.7.x, Python 2.7 is already installed on your system. If not, proceed with the next steps.
Step 3: Install Python 2.7
To install Python 2.7, you can use the package manager apt-get. Run the following command:
sudo apt-get install python2.7
This command will install Python 2.7 and its dependencies.
Step 4: Verify the Installation
After the installation is complete, verify it by checking the Python version:
python2.7 --version
This should return “Python 2.7.x”, confirming that Python 2.7 is successfully installed on your system.
Step 5: Install pip for Python 2.7
pip is a package manager for Python that allows you to install and manage additional packages that are not part of the Python standard library. To install pip for Python 2.7, first ensure you have wget installed, then download and run the get-pip.py script:
sudo apt-get install wget
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
sudo python2.7 get-pip.py
After running these commands, pip2 will be installed for Python 2.7.
Step 6: Using Python 2.7
You can now start using Python 2.7 on your system. To ensure you’re using Python 2.7 specifically, use python2.7 or pip2 for installing Python 2 packages.
Conclusion
Installing Python 2.7 on Ubuntu, Debian, and Linux Mint can be useful for running legacy Python applications. However, it’s strongly recommended to migrate your applications to Python 3 if possible, as Python 2.7 is no longer supported and may pose security risks. Always consider the implications of using outdated software in your projects.
47 Comments
great work man
Thanks, man
Reis helal lan.
Nice work.
great work man
Thank you very much, it worked without any issue.
Thank you!
Thank you!
Step 1 doesn’t work for Linux Mint 20.
boback@boback-XPS-15-9570:~$ 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).
boback@boback-XPS-15-9570:~$
Being a beginner at this, I have no idea how to proceed.
Hey, you have wrong url, should be https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
Thanks, I have updated the URL.
Works great thanks! but how then to install new packages and liberaries with pip install?
Thank you!
Thanks a lot Rahul.
Thanks RAHUL.
Thank you a lot!
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.
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.
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
You’re the man!!
Thanks a lot!
I have compleated all steps but it still shows 2.7.6 ?
Thanks a lot, It really helped me!
Hello sir, Thank u for such great tutorial…
It helped me alot.
Once again thank you 🙂
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
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]
Very Clear…Great one!!!
excuse me for wondering that how to cleanly remove them after installing because “make uninstall* seems not available
Thank you!
very straightforward setup for Windows Ubuntu Subsystem! Cheers!
Clean, sharp instructions, thanks kid 🙂
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
Thanks Rahul
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?) 😉
This was very helpful. I’m new to python and this worked on the first try.
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
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.
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).
equals, version wasn’t replace
Thanks dude, this worked a treat!
I followed instructions on Linux Mint Cinnamon 17.3 and ended up with latest python, but missing crucial modules like datetime and time.
Thanks for the article.
i would suggest running sudo apt-get update
before running the first two commands
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.
I get
E: Unable to locate package checkinstall
Thank you…. great!!
Thank you so much!
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.