how to install the latest python version on kali linux

How To Install the Latest Python Version on Kali Linux?

Python is always getting new updates, with many versions available at the same time. Different programs on your computer might need different versions of Python. This guide is here to help you install and use the Python version you need, even if it’s not in your Kali Linux’s default list.

On Kali Linux, unlike with other distributions, the latest version of Python is generally quickly available in the default repository. The recommended method to get the latest version is then to wait for it to be available with APT. But it’s also possible to install other versions manually if needed.

For this guide, we’re using Kali Linux as an example. While the steps should work on other Linux systems, especially ones based on Debian, some commands might need to be changed if you’re using a different Linux system.

Master Linux Commands
Your essential Linux handbook
Want to level up your Linux skills? Here is the perfect solution to become efficient on Linux. 20% off today!

Download now

How to know which Python version is installed

You can have more than one Python version on your Kali Linux at the same time. If you want to know the specific version number, type “python –version” or “python2 –version” in the command line.

Master your cyber security skills:
Secure your spot in the Accelerator Program, with early access to exclusive resources.
Get 1000+ classes, unlimited mentorship, and more.

On Kali Linux, you might have different commands like “python”, “python2”, or “python3”. All of these can work at the same time and give different results because you can have multiple Python versions installed.

The specific version you have depends on the newest one in the default list, which can be different for different Linux systems. If you use Debian, your Python version might be a few years old, and with Ubuntu, it might be a few months old.

I have found that Kali Linux gets the latest Python version installed way faster than my other distributions. So it’s generally not a problem to get it installed, you can simply use:
sudo apt upgrade
Or install it with:
sudo apt install python3
If you don’t have it installed yet.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!

But, if you need a specific Python version, keep reading this guide, I’ll tell you how to do that.

Check the latest Python version available

The simplest way to find the newest Python version is to visit Python’s official website. There, on the download page, you’ll see the newest versions, when they were released, and whether they’re still being updated.

The first table shows you the newest Python versions. Looking at the Download page, you’ll see that even though I’m using Kali Linux (which gets updates often compared to other systems), my Python version is more than 6 months old. So, for some programs, you might need to update it or try the prerelease one.

Install a specific Python version on Kali Linux

To install a specific Python version on Kali Linux, you need to get the source code from the official website and install it yourself:

  • Step 1: Go to the official website and download the newest Python version.
  • Step 2: Unpack the files you downloaded.
  • Step 3: Set up your system to use the new Python version.

Let’s look at how to do these steps.

Method 1: Use the package manager

On Kali Linux, new versions are quickly available with the package manager (APT), so check with it first.

Do a quick search to see if it’s already available there. You can, for example, use:
sudo apt search ^python3.12
This will list all packages starting with “python3.12” so you can quickly know if it’s already there.

As you can see, even if at the time of writing Python 3.11.4 is still the latest stable release (and already installed on my system), I can find Python 3.12 (prerelease) in the Kali rolling repository.

If I want to install it, I can just use:
sudo apt install python3.12

Method 2: Manual installation

If you can’t find the version you’re looking for with APT, or maybe don’t want to replace anything in your current setup, the alternative is to install Python manually by downloading the latest archive from the official website. Here is how to do this.

Download and extract the latest Python version

  • Go to the Python download page.
  • Scroll down to the table titled: “Looking for a specific release?”
  • Click on the “Download” link corresponding to the version you want to install.
    In my case, I will pick Python 3.10.2 as an example.
  • Scroll to the bottom of the next page, and find the list of download links:
  • Right-click on “Gzipped source tarball” and choose “Copy link address” from the browser contextual menu.
Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!

Open a terminal or connect via SSH to type the next commands.

  • Download the latest Python file with:
    wget https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz
    Replace the URL with the link you pasted in the previous step.
    wget <url>
  • Extract the files with:
    tar -zxvf Python-3.10.2.tgz
    Change the Python version if you downloaded another one.
    tar -zxvf <filename>

Configure and install Python’s latest version

Next, we need to turn the source code into a program, so we can install this Python version on your Kali Linux:

  • Open the folder where the sources are:
    cd Python-3.10.2
  • Run the configuration command:
    ./configure --enable-optimizations
    If you have an error, you probably need to install or update the missing components.
  • Finally, run this command to install the new version:
    sudo make altinstall

The difference between “make install” and “make altinstall” is that “make altinstall” won’t change the Python version that Kali Linux uses by default. This way, it won’t mess up anything. After this, I’ll show you how to switch to the new version (after you’ve checked that everything works with it).

Hide your IP address and location with a free VPN:
Try it for free now, with advanced security features.
2900+ servers in 65 countries. It's free. Forever.

Change the default Python version on Kali Linux

Each installed version of Python on your system puts a new executable under /usr/local/bin that you can use to run a program. For example, in my case, I now have:

  • python3.10: The one I installed manually
  • python3.11: The one that was installed automatically via the package manager.

But when I use “python3 –version”, I still use Python 3.11, not the one I installed manually.
To choose the version you want to run, you have two choices:

  • Always run a Python script with the exact version you intend to use, for example:
    python3.10 myscript.py
    Which is probably the safest option if you switch from one version to another regularly.
  • Or, you can replace the link in your /usr/local/bin folder to point to the version you want to use as default.

The “python3” command is simply a link to one of the installed versions, so it’s easy to change.
Here is what it looks like by default:

If you want to change the link, here are the commands:

  • Go to /usr/bin:
    cd /usr/bin
  • Remove the current link:
    sudo rm python3
  • Link the version you intend to use instead:
    sudo ln -s /usr/local/bin/python3.10.12 python3
  • Check that everything is fine:
    python3 --version
    It should now display the version you just installed (3.10.12 for me).

I hope this guide helped you learn about Python versions on Kali Linux. You now know that you can have more than one Python version at the same time and that it’s easy to change between them by using a different command.

Whenever you’re ready for more security, here are things you should think about:

- Break free from Gmail: You should be able to choose what happens to your data. With Proton, only you can read your emails. Get private email.

- Protect yourself online: Use a high-speed Swiss VPN that safeguards your privacy. Open-source, no activity logs. Get Proton VPN risk-free.

- Master Linux commands: A sure method to learn (and remember) Linux commands. Useful ones only, one at a time, with clear explanations. Download the e-book.

Similar Posts

Leave a Reply

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