Welcome to the blog on how to install Python in Kali Linux. Whether you're a cybersecurity enthusiast, a professional pentester, or a curious dude wanting to explore this field, then you are at the right place.
In this guide, I will tell you how to install Python, how to use and more things that you must know before using it. So let's start with an introduction.
What is Python?
Python is a versatile, powerful and high-level programming language. it become popular among developers and cybersecurity professionals.
You may notice from some years in the programming field everyone is talking about Python. Python is well-suited for a wide range of applications. Its ease of use and large community make it a great choice for both beginners and experienced programmers.
Now let's see some key features of Python.
Key features of Python
Easy to learn and read: Python is known for its clear and concise syntax, which makes it a good choice for beginners. It uses indentation to define code blocks, making the code structure easy to follow.
Nah, it's not that level easy as you think but with basic knowledge of programming, you can create simple programs in Python language.
General purpose: Python can be used for a wide variety of tasks, including web development, data science, machine learning, automation, and scientific computing. Most of the tech giants use Python.
Interpreted: Unlike compiled languages, Python code is not translated into machine code before it can be run. Instead, it is executed line by line by an interpreter.
This makes development faster and more flexible, as changes can be made and tested more quickly.
Object-oriented: Python supports object-oriented programming, which is a way of organizing code around objects that represent real-world entities. This can make code more modular and reusable.
Why Install Python in Kali Linux?
Now if we talk about Python’s benefits with Kali Linux then Python's simplicity, readability, and extensive libraries make it an ideal choice for various tasks, including penetration testing, network analysis, and scripting.
Now you know about Python let's start the installation process. But first, let us know what we need or what is requirements to install Python in Kali.
Requirements to install Python in Kali
Internet: Of course, we are going to download some packages from the Internet so we need a good internet connection.
Storage: Python needs around 90-100 MB of space for installation in Kali Linux. Make sure you have enough space.
How to install Python in Kali Linux
There are two methods to install Python in Kali Linux first one is using apt or Kali’s repository and in the second method we are going to use Python’s source code to install Python in Kali Linux.
Sometimes Python is preinstalled in Kali Linux. So first check if it is installed or not. To do this run the following command in the terminal.
python3 --version
If it is already installed then it will show the version of python.
If not then it will show something like this:
Now let's move to installation.
Method 1. Install Python Using Kali's repository
As earlier I said we can install Python using Kali Linux’s repository.
Update the repository
So to install Python using the repository first update the system by running the following command
sudo apt update
sudo apt upgrade
This will update your Kali Linux to the latest version of software and packages that will help in smooth installation.
Installing python
Now after updating the Kali Linux system. Run the following command in the terminal.
sudo apt install python3
Enter “Y” when it asks and this will install the python.
Here the python3 is the version of Python that will installed. If you want to install another version you can replace it with desired version.
After the process is completed run the python3 --version
to check the installation.
Method 2. Install python using source code
Now in this method, we are going to install Python using source. This method is useful in specific conditions when we need to install a specific version that is not available in the repository.
Pls note this method needs expertise so if you can install Python using apt then go with apt.
Download source code of Python
So first we will download the source code, for this go to Python’s official website and download the desired version (.tgz file).
Install Dependencies
While the package downloading install the Dependencies required for Python by running the following command.
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev checkinstall
Extract the Archive
Now Extract the tarball file by running the following command in the terminal.
tar xzf Python-X.Y.Z.tgz
After that move to the directory where you extract the tar file
cd Python-X.Y.Z
Replace <Python-X.Y.Z>
with the actual name of the directory.
Configure and Build
Now run the following commands to Configure and Build
./configure --enable-optimizations
sudo make altinstall
Use "altinstall" to avoid conflicts with the system Python.
Verify Installation
Now run the following command to verify if Python is successfully installed or not.
python3.11 --version
Optional: Add Python to PATH (if using altinstall):
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
And done, we have successfully installed Python.
Now we have installed Python in Kali let's know how to run a Python program in Kali Linux.
How to Run Python Programmes in Kali Linux
So for this first, we will create a Python script. use any code editor to make the script.
Now save your program with any name, and I will give myscript.py. Move to the directory where you saved your script. Then run the following command to run that Python script.
python3 myscript.py
It will print or run anything you added to the script.
How to update Python in Kali Linux
Now if there is a new version of Python and you want to upgrade your Python version then follow the below steps:
Update package lists
like all the time first we will update our package list.
sudo apt update
Upgrade Python
To upgrade Python to the latest version run the following command.
sudo apt upgrade python3 # Upgrade Python 3 specifically (if desired)
sudo apt upgrade
Beyond Basics: Enhance your Python Experience in Kali Linux
In the earlier parts, we talked about the basics of setting up and using Python. Now, we'll go further and explore some advanced techniques to make your Python experience in Kali Linux even better.
Virtual Environments
Imagine working on multiple projects, each requiring different Python libraries and versions. Using a single global environment can lead to conflicts and version management headaches. This is where virtual environments come in:
- Virtual Environments create isolated environments for each project, ensuring you have the exact dependencies required without affecting other projects.
- To create a virtual environment, we use the
venv
module included with Python 3 (orvirtualenv
if not available)
So to create a virtual environment first install venv. Run the following command
apt install python3.11-venv
Activate the environment
Now after installing venv run the following command to create a virtual environment.
python3 -m venv my_project_env
This will activate the environment named my_project_env
Once activated, package management commands (like pip) will affect only this isolated environment. Replace my_project_env
with the name you want to give to the virtual environment.
Package Management with pip
pip is the package manager for Python. It helps you install, upgrade, and uninstall Python libraries.
Run the following command if you don't have installed pip in your Kali Linux system.
sudo apt install pip
This will install pip and then you can use it for managing packages.
Install a package:
pip3 install <package_name>
Replace <package_name>
with the name of the package that you want to install. For example, I am installing the requests
package that is used for making HTTP requests in Python.
List installed packages
pip3 list
This command shows all the installed packages.
Uninstall a package
pip3 uninstall <package_name>
Replace <package_name>
with the name of the package and this will remove that package. For example, let's uninstall requests that we installed earlier.
FAQs
Is Python necessary for using Kali Linux?
While not mandatory, Python greatly enhances Kali Linux's functionality by providing access to a plethora of cybersecurity tools and scripts.
Can I install multiple Python versions in Kali Linux?
Yes, it's possible to install and manage multiple Python versions concurrently, either through package managers or manual installation methods.
Is it recommended to install Python from source in Kali Linux?
Installing Python from source allows for greater customization but may require additional effort compared to using package managers. It's advisable for advanced users or specific use cases.
How often should I update Python in Kali Linux?
It's advisable to update Python whenever there are new versions available to access the latest features, security patches, and bug fixes. Keeping Python up-to-date ensures optimal performance and compatibility with the latest tools and scripts.
Read also:
How to install Visual Studio Code in Kali Linux
Is Garuda Linux Good for Programming?
Conclusion
In this article, I have told almost everything that you need to know before starting development with Linux or learning Python. I have covered installation, uses, upgrades and then some advanced techniques that help you to develop with Python in Kali Linux.
if you like our articles then follow us on social media and subscribe to our newsletter to never miss any important updates.