Installing pip On Ubuntu 22.04 LTS

In this short tutorial we will learn how to install pip (Package Installer for Python) on Ubuntu 22.04 LTS Linux operating system. We will install pip2 and pip3. Most distributions of Python come with pip preinstalled. Starting from Ubuntu 20.04, Python 2 is not default repository and available for installation from the Universe repository while Python 3 is included in the base system installation. For this reason, users are advised to switch to Python 3.

1. How To Install pip2 On Ubuntu 22.04

To install pip2 we need to use get-pip.py script, because pip for Python 2 is not included in the Ubuntu 22.04 repositories. The installation will be as follow :

  1. Update Repository
  2. Adding Universe Repository
  3. Install Python 2
  4. Download get-pip.py Script And Install pip
  5. Verify pip Installation

1.1. Update Ubuntu 22.04 Repository

By updating repository, we will refresh our system to the latest package version, this task is performed by submitting command line :

$ sudo apt update

1.2. Add Universe Repository

We will add universe repository to our Ubuntu system, by submitting command line :

$  sudo add-apt-repository universe

Output :

ramans@infodiginet:~$  sudo add-apt-repository universe
Adding component(s) 'universe' to all repositories.
Press [ENTER] to continue or Ctrl-c to cancel.
Hit:2 http://id.archive.ubuntu.com/ubuntu jammy InRelease                                             
Ign:1 http://ads.indosatooredoo.com/ads-request?j=9&t=2&i=171613977&s=I04006167219388948013&a=http://www.apache.org/dist/cassandra/debian 40x InRelease
Hit:3 http://apt.postgresql.org/pub/repos/apt jammy-pgdg InRelease                                    
Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease                                      
Hit:6 http://id.archive.ubuntu.com/ubuntu jammy-updates InRelease                                     
Hit:7 http://id.archive.ubuntu.com/ubuntu jammy-backports InRelease                                   
Ign:8 https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 InRelease                             
Hit:9 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease                          
Hit:10 https://repos.influxdata.com/ubuntu jammy InRelease                                  
Hit:11 https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 Release
Get:5 https://downloads.apache.org/cassandra/debian 40x Release [3.020 B]
Get:13 https://downloads.apache.org/cassandra/debian 40x Release.gpg [833 B]   
Ign:14 http://download.webmin.com/download/repository sarge InRelease
Hit:15 http://download.webmin.com/download/repository sarge Release
Fetched 3.853 B in 3s (1.145 B/s)
Reading package lists... Done

1.3. Install Python 2

In this step, we will install Python 2, by submitting following command line :

$ sudo apt udpate
$ sudo apt install python2

Output :

ramans@infodiginet:~$ sudo apt install python2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libpython2-stdlib python2-minimal python2.7 python2.7-minimal
Suggested packages:
  python2-doc python-tk python2.7-doc binfmt-support
The following NEW packages will be installed:
  libpython2-stdlib python2 python2-minimal python2.7 python2.7-minimal
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 1.681 kB of archives.
After this operation, 4.340 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://id.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python2.7-minimal amd64 2.7.18-13ubuntu1.1 [1.394 kB]
Get:2 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 python2-minimal amd64 2.7.18-3 [20,8 kB]               
Get:3 http://id.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python2.7 amd64 2.7.18-13ubuntu1.1 [250 kB]      
Get:4 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 libpython2-stdlib amd64 2.7.18-3 [7.432 B]               
Get:5 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 python2 amd64 2.7.18-3 [9.098 B]                         
Fetched 1.681 kB in 7s (235 kB/s)                                                                                       
Selecting previously unselected package python2.7-minimal.
(Reading database ... 271508 files and directories currently installed.)
Preparing to unpack .../python2.7-minimal_2.7.18-13ubuntu1.1_amd64.deb ...
Unpacking python2.7-minimal (2.7.18-13ubuntu1.1) ......................................................................] 
Selecting previously unselected package python2-minimal................................................................] 
Preparing to unpack .../python2-minimal_2.7.18-3_amd64.deb ...
Unpacking python2-minimal (2.7.18-3) ...
Selecting previously unselected package python2.7.
Preparing to unpack .../python2.7_2.7.18-13ubuntu1.1_amd64.deb ...
Unpacking python2.7 (2.7.18-13ubuntu1.1) ...
Selecting previously unselected package libpython2-stdlib:amd64.
Preparing to unpack .../libpython2-stdlib_2.7.18-3_amd64.deb ...
Unpacking libpython2-stdlib:amd64 (2.7.18-3) ...
Setting up python2.7-minimal (2.7.18-13ubuntu1.1) ...
Linking and byte-compiling packages for runtime python2.7...
Setting up python2-minimal (2.7.18-3) ...
Selecting previously unselected package python2.
(Reading database ... 271561 files and directories currently installed.)
Preparing to unpack .../python2_2.7.18-3_amd64.deb ...
Unpacking python2 (2.7.18-3) ...
Setting up python2.7 (2.7.18-13ubuntu1.1) ...
Setting up libpython2-stdlib:amd64 (2.7.18-3) ...
Setting up python2 (2.7.18-3) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...

1.4. Download get-pip.py Script And Install pip2

In this step, we will download get-pip.py script and install pip2. We will use command line :

$ curl https://bootstrap.pypa.io/pip/2.7/get-pip.py –output get-pip.py
$ sudo python2 get-pip.py

Output :

ramans@infodiginet:~$ curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1863k 100 1863k 0 0 1680k 0 0:00:01 0:00:01 --:--:-- 1680k
ramans@infodiginet:~$ sudo python2 get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting pip<21.0
Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 1.6 MB/s 
Collecting setuptools<45
Downloading setuptools-44.1.1-py2.py3-none-any.whl (583 kB)
|████████████████████████████████| 583 kB 2.4 MB/s 
Collecting wheel
Downloading wheel-0.37.0-py2.py3-none-any.whl (35 kB)
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-20.3.4 setuptools-44.1.1 wheel-0.37.0

1.5 Verify pip2 Installation

To verify pip installation, we will query its version by submitting command line :

$ pip2 --version

Output :

ramans@infodiginet:~$ pip2 --version
pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

How To Install pip3 On Ubuntu 22.04

Since Python 3 has been included in Ubuntu 22.04 base system installation, we will easily install pip3 on the system. To install pip3, we will do the following steps :

  1. Update system repository
  2. Install pip for Python 3
  3. Verify pip3 version

2.1 Update System Repository

In this step we will update system repository. We will refresh our system to the latest package version. We will do the following command line :

$ sudo apt update
$ sudo apt upgrade

2.2 Install pip for Python 3

To install pip for Python 3 (pip3) we will do the command line.

$ sudo apt install python3-pip

Output :

ramans@infodiginet:~$ sudo apt install python3-pip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  javascript-common libexpat1-dev libjs-jquery libjs-sphinxdoc libjs-underscore libpython3-dev libpython3.10-dev
  python3-dev python3-distutils python3-setuptools python3-wheel python3.10-dev
Suggested packages:
  python-setuptools-doc
The following NEW packages will be installed:
  javascript-common libexpat1-dev libjs-jquery libjs-sphinxdoc libjs-underscore libpython3-dev libpython3.10-dev
  python3-dev python3-distutils python3-pip python3-setuptools python3-wheel python3.10-dev
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 7.842 kB of archives.
After this operation, 33,6 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 javascript-common all 11+nmu1 [5.936 B]
Get:2 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libexpat1-dev amd64 2.4.7-1ubuntu0.2 [147 kB]
Get:3 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 libjs-jquery all 3.6.0+dfsg+~3.5.13-1 [321 kB]                  
Get:4 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 libjs-underscore all 1.13.2~dfsg-2 [118 kB]                     
Get:5 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 libjs-sphinxdoc all 4.3.2-1 [139 kB]                            
Get:6 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libpython3.10-dev amd64 3.10.6-1~22.04.2 [4.755 kB]     
Get:7 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libpython3-dev amd64 3.10.6-1~22.04 [7.166 B]           
Get:8 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3.10-dev amd64 3.10.6-1~22.04.2 [507 kB]          
Get:9 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3-distutils all 3.10.6-1~22.04 [139 kB]           
Get:10 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3-dev amd64 3.10.6-1~22.04 [26,0 kB]             
Get:11 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 python3-setuptools all 59.6.0-1.2 [339 kB]                     
Get:12 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-wheel all 0.37.1-2 [31,9 kB]                       
Get:13 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-pip all 22.0.2+dfsg-1 [1.306 kB]                   
Fetched 7.842 kB in 4min 19s (30,3 kB/s)                                                                                   
Selecting previously unselected package javascript-common.
(Reading database ... 271578 files and directories currently installed.)
Preparing to unpack .../00-javascript-common_11+nmu1_all.deb ...
Unpacking javascript-common (11+nmu1) ...
Selecting previously unselected package libexpat1-dev:amd64.
Preparing to unpack .../01-libexpat1-dev_2.4.7-1ubuntu0.2_amd64.deb ...
Unpacking libexpat1-dev:amd64 (2.4.7-1ubuntu0.2) ...
Selecting previously unselected package libjs-jquery.
Preparing to unpack .../02-libjs-jquery_3.6.0+dfsg+~3.5.13-1_all.deb ...
Unpacking libjs-jquery (3.6.0+dfsg+~3.5.13-1) ...
Selecting previously unselected package libjs-underscore.
Preparing to unpack .../03-libjs-underscore_1.13.2~dfsg-2_all.deb ...
Unpacking libjs-underscore (1.13.2~dfsg-2) ...
Selecting previously unselected package libjs-sphinxdoc.
Preparing to unpack .../04-libjs-sphinxdoc_4.3.2-1_all.deb ...
Unpacking libjs-sphinxdoc (4.3.2-1) ...
Selecting previously unselected package libpython3.10-dev:amd64.
Preparing to unpack .../05-libpython3.10-dev_3.10.6-1~22.04.2_amd64.deb ...
Unpacking libpython3.10-dev:amd64 (3.10.6-1~22.04.2) ...
Selecting previously unselected package libpython3-dev:amd64.
Preparing to unpack .../06-libpython3-dev_3.10.6-1~22.04_amd64.deb ...
Unpacking libpython3-dev:amd64 (3.10.6-1~22.04) ...
Selecting previously unselected package python3.10-dev.
Preparing to unpack .../07-python3.10-dev_3.10.6-1~22.04.2_amd64.deb ...
Unpacking python3.10-dev (3.10.6-1~22.04.2) ...
Selecting previously unselected package python3-distutils.
Preparing to unpack .../08-python3-distutils_3.10.6-1~22.04_all.deb ...
Unpacking python3-distutils (3.10.6-1~22.04) ...
Selecting previously unselected package python3-dev.
Preparing to unpack .../09-python3-dev_3.10.6-1~22.04_amd64.deb ...
Unpacking python3-dev (3.10.6-1~22.04) ...
Selecting previously unselected package python3-setuptools.
Preparing to unpack .../10-python3-setuptools_59.6.0-1.2_all.deb ...
Unpacking python3-setuptools (59.6.0-1.2) ...
Selecting previously unselected package python3-wheel.
Preparing to unpack .../11-python3-wheel_0.37.1-2_all.deb ...
Unpacking python3-wheel (0.37.1-2) ...
Selecting previously unselected package python3-pip.
Preparing to unpack .../12-python3-pip_22.0.2+dfsg-1_all.deb ...
Unpacking python3-pip (22.0.2+dfsg-1) ...
Setting up python3-distutils (3.10.6-1~22.04) ...
Setting up javascript-common (11+nmu1) ...
apache2_invoke: Enable configuration javascript-common
Setting up python3-setuptools (59.6.0-1.2) ...
Setting up python3-wheel (0.37.1-2) ...
Setting up libexpat1-dev:amd64 (2.4.7-1ubuntu0.2) ...
Setting up libpython3.10-dev:amd64 (3.10.6-1~22.04.2) ...
Setting up python3-pip (22.0.2+dfsg-1) ...
Setting up python3.10-dev (3.10.6-1~22.04.2) ...
Setting up libjs-jquery (3.6.0+dfsg+~3.5.13-1) ...
Setting up libjs-underscore (1.13.2~dfsg-2) ...
Setting up libpython3-dev:amd64 (3.10.6-1~22.04) ...
Setting up libjs-sphinxdoc (4.3.2-1) ...
Setting up python3-dev (3.10.6-1~22.04) ...
Processing triggers for man-db (2.10.2-1) ...

2.3. Verify pip3 version

After pip for Python 3 installation is completed, we need to verify the version by submitting command line :

$ pip3 –version

Output :

ramans@infodiginet:~$ pip3 --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)

Conlusion

In this short tutorial, we have learned how to install pip2 and pip3 on Ubuntu 22.04 LTS operating system

(Visited 182 times, 1 visits today)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *