Python 3 is a powerful and versatile programming language widely used for various tasks, from web development to data science, security automation, and AI and ML. Recent versions of Kali Linux come with Python 3 pre-installed. For some reason if you want a different version than the one already installed or you’re using an old version of Kali Linux which doesn’t have python 3 pre-installed. In this article, we will install Python 3 using two methods
Table of Content
Method 1 : Using APT package manager
Step 1 : Update package list
To make sure we are getting latest version of python, update package list using apt update command.
sudo apt update -y
Step 2 : Install Python 3
Once repositories are up to date, we will install python using apt install command.
sudo apt install python3 -y
Step 3 : Verify installation
Once, installation is done, verify installation using python –version command.
python --version
Method 2 : Compiling from sources
Step 1 : Installing dependencies
In order to install python 3 from Tarball package, we will need to download required dependencies using apt install command as follows
sudo apt install build-essential zlib1g-dev libncurses-devlib libgdbm-dev libnss3 libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev -y
Step 2 : download archive
In this step, we will download official Tarball package from official python repository using wget command.
wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tgz
Step 3 : Extract the archive
Once downloading is completed, we will extract the package using tar -xvf command.
tar -xvf Python-3.12.2.tgz
Step 4 : Navigate to the extracted directory
Once extracted, navigate to extracted directory using cd command.
cd Python-3.12.2
Step 5: Configure and build
Once we are in extracted python directory, use following commands to make configurations and installation.
./configure
Once configuration is done, we will install python with make install command.
sudo make install
Step 6 : Verify installation
Once, installation is done, verify installation using python –version command.
python --version
How to Install Python 3 on Kali Linux – FAQs
How do I manage multiple Python versions on my system?
If both Python 2 and 3 are installed, use python3 explicitly to execute scripts using the desired Python 3 version. Alternatively, you can use version managers like pyenv or conda for more efficient management of multiple Python versions.
How do I keep Python 3 updated?
If you used Method 1, simply run sudo apt update && sudo apt upgrade regularly. For Method 2, download the latest source code, recompile, and install.
Do I need to install Python 3 if I already have Python in Kali Linux?
Recent versions of Kali Linux (2019.1 and later) come pre-installed with Python 3.6 or later. You can check your installed Python version using the command python3 –version. If the command outputs a version number, then you already have Python 3 installed. However, if you need a specific version not included in your Kali installation, you might need to install it using second method mentioned in the article.
Conclusion
In this article we have discussed two methods for installing Python 3 in Kali Linux. For most users, the recommended approach is to use the Kali repositories (using APT Package Manager) for ease of installation, compatibility, and regular security updates. However, if you have specific requirements or need to install a development version, compiling from source can be an option.