- Check latest python version installed on Ubuntu
- How to install Python on Ubuntu
- Update Python in Ubuntu to Latest Version
- How to uninstall Python in Ubuntu
Check latest python version installed on Ubuntu
This is good news that Python comes pre-installed in Ubuntu 19.04. But question is still remain How will you check Latest python version on your Ubuntu operating system?
Most of tools and utility having special switch for checking version, same python have.
You can use following code to check latest python version
[email protected]:~$python3 --version Python 3.7.3 [email protected]:~$
How to install Python on Ubuntu
[email protected]:~$sudo apt-get install python3
If you want to install python on Ubuntu from another source then first get the link from Python’s official website, and download it manually or with help of wget utility.
I am using wget to download latest version.
[email protected]:~$wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz --2019-06-19 10:39:49-- https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz Resolving www.python.org (www.python.org)... 22.214.171.124, 2a04:4e42:42::223 Connecting to www.python.org (www.python.org)|126.96.36.199|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 22973527 (22M) [application/octet-stream] Saving to: ‘Python-3.7.3.tgz’ Python-3.7.3.tgz 100%[==============================>] 21.91M 881KB/s in 30s 2019-06-19 10:40:19 (760 KB/s) - ‘Python-3.7.3.tgz’ saved [22973527/22973527]
Next step to extract downloaded file.
$tar -xvf Python-3.7.3.tgz
[email protected]:~$tar -xvf Python-3.7.3.tgz
Move to Python-3.7.3 file after completing extraction process. Use the following command.
[email protected]:~$cd Python-3.7.3/ [email protected]:~/Python-3.7.3/$
Next step to run configure script to check the build.
Once the checking process done use following two commands to install python on Ubuntu.
[email protected]:~/Python-3.7.3/$sudo make
[email protected]:~/Python-3.7.3/$sudo make install
zipimport.ZipImportError: can't decompress data; zlib not available make: *** [Makefile:1130: install] Error 1 [email protected]:~/Python-3.7.3/$
If you have got above error, It means one more tool required to complete this task (make install).
So what is now? One more task.
You will have to install one more tool to complete successfully install Python on Ubuntu. The tool name is zlib1g-dev and you can install by running following command.
[email protected]:~/Python-3.7.3/$sudo apt-get install zlib1g-dev Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: zlib1g-dev 0 upgraded, 1 newly installed, 0 to remove and 166 not upgraded. Need to get 172 kB of archives. After this operation, 437 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu disco/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-1ubuntu2 [172 kB] Fetched 172 kB in 3s (59.7 kB/s) Selecting previously unselected package zlib1g-dev:amd64. (Reading database ... 136237 files and directories currently installed.) Preparing to unpack .../zlib1g-dev_1%3a1.2.11.dfsg-1ubuntu2_amd64.deb ... Unpacking zlib1g-dev:amd64 (1:1.2.11.dfsg-1ubuntu2) ... Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-1ubuntu2) ... Processing triggers for man-db (2.8.5-2) ... [email protected]:~/Python-3.7.3/$
After installing the zlib1g-dev, run again both command $sudo make and $sudo make install.
I hope you will not get any error.
Update Python in Ubuntu to Latest Version
As you have seen above, I have python version is python 3.7.3 and the latest version is the same. This is really good news for me.
If you have old version of python installed on Ubuntu then you can update by using following commands:
$sudo apt-get udpate
$sudo apt-get upgrade python3
First command for update repository and second one is to update python.
[email protected]:~$sudo apt-get upgrade python3 Reading package lists... Done Building dependency tree Reading state information... Done python3 is already the newest version (3.7.3-1). python3 set to manually installed. Calculating upgrade... Done The following packages have been kept back: linux-generic linux-headers-generic linux-image-generic The following packages will be upgraded: linux-libc-dev openvpn 2 upgraded, 0 newly installed, 0 to remove and 3 not upgraded. Need to get 1,534 kB of archives. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n]
Warning to update python on Ubuntu
If you have installed python on Ubuntu or other Linux distribution from other source. You have to following steps.
- Uninstall python on Ubuntu
- Download latest version from official website
- Again Install Python on Ubuntu.
How to uninstall Python on Ubuntu
Why do you want to uninstall python in Ubuntu or another Linux machine?
Why? Let me know in the comment box.
Whatever reason you have to uninstall python, but only two ways exist. If you have installed python from the repository (using the command $sudo apt-get install pyhton3.7). Then you can use the following command to uninstall python from your Ubuntu machine completely.
Warning: Don’t mention major version in command like Python3, because the python3 version is used by your system. Your system will get crashed. You can mention minor versions like python3.6 or Python3.7
[email protected]:~$sudo apt remove python3.7 Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: apg apport-symptoms aptdaemon-data avahi-utils command-not-found-data cups-pk-helper dc diffstat distro-info-data fprintd gettext gir1.2-accountsservice-1.0 gir1.2-atspi-2.0 gir1.2-dbusmenu-glib-0.4 gir1.2-dee-1.0 gir1.2-gck-1 gir1.2-gcr-3 gir1.2-gdesktopenums-3.0 gir1.2-gdm-1.0 gir1.2-geoclue-2.0 gir1.2-geocodeglib-1.0 gir1.2-gnomebluetooth-1.0 gir1.2-gnomedesktop-3.0 gir1.2-goa-1.0 gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 gir1.2-gtksource-4 gir1.2-gudev-1.0 gir1.2-gweather-3.0 gir1.2-ibus-1.0
Press Y for confirmation to remove python from your system
Way 2: If you have installed python from other sources, Then you can remove only python files from the path /usr/local/bin. To do so you can run the following commands:
$sudo rm /usr/local/bin/py*
$sudo rm /usr/local/bin/pip*
$sudo rm /usr/local/bin/idle*
$sudo rm /usr/local/bin/2to3*
$sudo rm /usr/local/bin/easy_install-3.7
You have learned how to install python on Linux, If you have any question please leave in the comment box.
Thanks for Reading
Buy Hosting from HostWind