How to Install Python 3 on Kali Linux

In this tutorial, you will learn how to get the latest version of Python and pip installed on Kali Linux. Python can be installed from the Kali software repository with apt command, or we can get the latest Python release or pre-release from Python.org. We’ll cover both methods below.

Install From Kali Repo

Step 1. To check what version of Python is installed in your system:

$ python3 --version
Python 3.10.8

Step 2. To install the latest version of Python, execute the following command:

$ sudo apt update
$ sudo apt install python3

Step 3. To install pip on Kali (the package installer for Python):

$ sudo apt install python3-pip

Step 4. To launch Python, simply execute the next command:

$ python3

Install Latest Version From Official Download

The next method takes a few additional steps, but ensures that you download and install the absolute latest Python release.

Step 1. Before installing Python, always make sure that you have your system up to date:

$ sudo apt update
$ sudo apt upgrade

Step 2. Next, we’ll install the dependencies:

$ sudo apt install build-essential pkg-config zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev

Step 3. Navigate to the Python download page and choose from either the latest stable release or pre-release version. Download either the compressed gzipped tarball, or the xz tarball.

Step 4. Extract the downloaded file with tar command:

$ cd ~/Downloads
$ tar -xf Python-*

Step 5. Change into the directory where the Python source was extracted:

$ cd Python*/

Step 6. Optimize the Python build process by executing:

$ ./configure --enable-optimizations

Step 7. Once done, we build the Python source with the make command followed by the -j parameter and the number of cores that you have in your system. You can check this by running the nproc command.

$ make -j 2

Step 8. Finally, proceed to install Python:

$ sudo make altinstall

Note: the altinstall option is necessary to ensure that the system-default Python files won’t be touched.

Step 9. To verify that the installation was successful, execute the following command and you should see the expected version number:

$ python3.11 --version

Note: Replace 3.11 with the version number that you installed.

Leave a Comment

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