How to Uninstall Python in Ubuntu

  1. Uninstalling Python Using the Terminal
  2. Purging Python Packages
  3. Removing Python Dependencies
  4. Verifying Python Uninstallation
  5. Conclusion
  6. FAQ
How to Uninstall Python in Ubuntu

Uninstalling Python from your Ubuntu operating system may seem daunting, especially for those who are new to Linux. However, with the right steps, you can easily remove Python and free up space or resolve conflicts with other software. This article will guide you through the process of uninstalling Python in Ubuntu, ensuring you have all the necessary information to do so safely and effectively.

Whether you need to uninstall Python for development purposes or simply to clean up your system, understanding the methods available can make the process smoother. In this guide, we will explore several ways to uninstall Python, ensuring you have a comprehensive understanding of each method. Let’s dive in!

Uninstalling Python Using the Terminal

The most straightforward way to uninstall Python from Ubuntu is through the terminal. This method is efficient and allows you to remove Python completely from your system. First, open your terminal by searching for “Terminal” in your applications or using the shortcut Ctrl + Alt + T.

To begin the uninstallation process, you can use the following command:

sudo apt-get remove python3

This command will remove the Python 3 package from your system. If you have Python 2 installed, you can replace python3 with python2 in the command above.

After executing the command, you may be prompted to enter your password. Once entered, the system will begin the uninstallation process. You might see output indicating the progress of the removal.

Output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  python3
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 10.5 MB disk space will be freed.

This output confirms that Python has been successfully removed from your system, along with the space it occupied.

Using the terminal is beneficial because it allows you to see real-time feedback on the process. Additionally, you can easily modify the command to uninstall specific versions of Python if you have multiple versions installed.

Purging Python Packages

If you want to ensure that all configuration files related to Python are also removed, you can use the purge command instead of remove. This is particularly useful if you want a clean slate without any remnants of the Python installation.

To purge Python, simply run the following command in your terminal:

sudo apt-get purge python3

This command works similarly to the remove command but goes a step further by deleting configuration files associated with the package.

After executing the command, you will again be prompted for your password, and the output will inform you of the actions being taken.

Output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  python3
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 10.5 MB disk space will be freed.

This output indicates that Python 3 has been purged, including any configuration files that were left behind. Purging is a great option if you plan to reinstall Python later or if you want to ensure that no old settings interfere with your new installation.

Removing Python Dependencies

When you uninstall Python, there may be additional packages or dependencies that were installed alongside it. To remove these unnecessary packages and free up space, you can use the autoremove command.

After uninstalling Python, run the following command:

sudo apt-get autoremove

This command will automatically remove any packages that were installed as dependencies for Python but are no longer needed.

Output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  python3-pkg-resources python3-requests
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 1.2 MB disk space will be freed.

This output shows which packages will be removed along with the amount of disk space that will be freed. Running autoremove is an excellent practice after uninstalling software, as it helps keep your system clean and efficient.

Verifying Python Uninstallation

After you’ve uninstalled Python, it’s essential to verify that it has been successfully removed from your system. You can do this by checking the installed packages.

To check if Python is still present, use the following command:

python3 --version

If Python has been successfully uninstalled, you should see an error message indicating that the command is not found.

Output:

Command 'python3' not found, but can be installed with:
sudo apt install python3

This output confirms that Python 3 is no longer installed on your system. If you receive this message, you can be assured that the uninstallation was successful.

Verifying the uninstallation is a crucial step, especially if you plan to install a different version of Python or switch to another programming language.

Conclusion

Uninstalling Python from Ubuntu is a straightforward process that can be accomplished through the terminal using various commands. Whether you choose to remove, purge, or clean up dependencies, understanding these methods ensures that you can manage your Python installations effectively.

With the steps outlined in this article, you can easily uninstall Python and maintain a tidy Ubuntu environment. Remember to verify the uninstallation and clean up any unnecessary packages to keep your system running smoothly. Happy coding!

FAQ

  1. How do I check if Python is installed on Ubuntu?
    You can check if Python is installed by running the command python3 --version in the terminal.

  2. Can I uninstall Python without using the terminal?
    Yes, you can use the Ubuntu Software Center to uninstall Python, but using the terminal is more efficient.

  3. What happens if I uninstall Python?
    Uninstalling Python may affect applications that depend on it. Be sure to check compatibility before proceeding.

  4. Is it safe to remove Python from Ubuntu?
    While you can remove Python, be cautious as many system tools rely on it. It’s best to keep at least one version installed.

  5. How can I reinstall Python after uninstalling it?
    You can reinstall Python by running the command sudo apt install python3 in the terminal.

Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Salman Mehmood avatar Salman Mehmood avatar

Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.

LinkedIn