This post is about changing the default Python version in Kali

How to change the default version of Python in Kali Linux Link to heading

──(rocky㉿kali)-[~]
└─$ ls /usr/bin/python*
/usr/bin/python     /usr/bin/python3           /usr/bin/python3-config      /usr/bin/python3-qr          /usr/bin/python-faraday
/usr/bin/python2    /usr/bin/python3.9         /usr/bin/python3-futurize    /usr/bin/python3-tor-prompt
/usr/bin/python2.7  /usr/bin/python3.9-config  /usr/bin/python3-pasteurize  /usr/bin/python3-wsdump

┌──(rocky㉿kali)-[~]
└─$ python --version
Python 2.7.18

┌──(rocky㉿kali)-[~]
└─$ python3 --version                         
Python 3.9.7

┌──(rocky㉿kali)-[~]
└─$ which python3                                                                                
/usr/bin/python3

┌──(rocky㉿kali)-[~]
└─$ alias python=/usr/bin/python3                       

┌──(rocky㉿kali)-[~]
└─$ python --version 
Python 3.9.7

Please note that above commands are just temporry and once you close the terminal or session the python version will go back to Python2.7.18( earlier one). Or if you want to undo the chnages or revert back to previous version you can do unalias command.

└─$ alias                                                                                                                                                             130 ⨯
diff='diff --color=auto'
egrep='egrep --color=auto'
fgrep='fgrep --color=auto'
grep='grep --color=auto'
history='history 0'
ip='ip --color=auto'
l='ls -CF'
la='ls -A'
ll='ls -l'
ls='ls --color=auto'
python=/usr/bin/python3
which-command=whence

┌──(rocky㉿kali)-[~]
└─$ unalias python=/usr/bin/python3

To make it permananat and switch between version 2.7 and 3.9 i suggest to use below method

──(rocky㉿kali)-[~]
└─$ ls /usr/bin/python*
/usr/bin/python     /usr/bin/python3           /usr/bin/python3-config      /usr/bin/python3-qr          /usr/bin/python-faraday
/usr/bin/python2    /usr/bin/python3.9         /usr/bin/python3-futurize    /usr/bin/python3-tor-prompt
/usr/bin/python2.7  /usr/bin/python3.9-config  /usr/bin/python3-pasteurize  /usr/bin/python3-wsdump
                                                                                                                                                                            
┌──(rocky㉿kali)-[~]
└─$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
[sudo] password for rocky: 
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
                                                                                                                                                                            
┌──(rocky㉿kali)-[~]
└─$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 2
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python (python) in auto mode
                                                                                                                                                                            
┌──(rocky㉿kali)-[~]
└─$ sudo update-alternatives --config python                                      
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.9   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.9   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 0
──(rocky㉿kali)-[~]
└─$ python --version
Python 3.9.7
                                                                                                                                                                            
┌──(rocky㉿kali)-[~]
└─$ update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.9
                                    

How to Switch to python 2.7 Link to heading