Linux MintUbuntu Based

How To Install Python on Linux Mint 21

Install Python on Linux Mint 21

In this tutorial, we will show you how to install Python on Linux Mint 21. Python, a versatile and powerful programming language, has become an essential tool for developers across various domains. Its simplicity, readability, and extensive library support make it an ideal choice for beginners and experienced programmers alike.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Python programming language on a Linux Mint 21.

Prerequisites

  • A server running one of the following operating systems: Linux Mint 21.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • While we’ll guide you through the process, a basic understanding of the command line will be beneficial. If you’re new to the CLI, you might want to acquaint yourself with some fundamental commands.
  • An active internet connection.
  • Administrative privileges are essential for installing and configuring software on your system. Ensure that you have superuser or sudo access.

Install Python on Linux Mint 21

Step 1. Before proceeding with the Python installation, ensure your Linux Mint system is up to date. Open a terminal and execute the following commands:

sudo apt update
sudo apt upgrade
sudo apt install software-properties-common

This command will refresh the package list and upgrade any outdated packages to their latest versions, ensuring a smooth and trouble-free Python installation.

Step 2. Adding the Python PPA Repository.

To access the latest Python versions, we’ll add the deadsnakes PPA repository to our system. The deadsnakes PPA is maintained by a trusted community and provides a wide range of Python versions for easy installation. To add the PPA, run the following command:

sudo add-apt-repository ppa:deadsnakes/ppa

Press Enter when prompted to confirm the addition of the repository. After adding the PPA, it’s essential to update the package list to include the newly available Python packages. Run the following command:

sudo apt update

Step 3. Installing Python on Linux Mint 21.

With the deadsnakes PPA repository added and the package list updated, we can now proceed with installing Python. Linux Mint 21 allows you to install multiple Python versions side by side, giving you the flexibility to choose the version that best suits your needs. To install a specific Python version, use the following command:

sudo apt install python3.12

To check the installed Python versions, open the terminal and run:

python3 --version

Step 4. Setting Python as the Default Version.

If you have multiple Python versions installed and wish to set the newly installed version as the default, use the update-alternatives command:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1

Step 5. Installing and Managing Python Packages with Pip.

Pip is Python’s package installer. Install pip for the newly installed Python version:

sudo apt install python3-pip

Use pip to install, update, and remove Python packages:

pip3 install package_name
pip3 uninstall package_name

Step 6. Configuring the Python Environment.

For a more isolated and customizable Python environment, consider using virtual environments:

python3 -m venv myenv
source myenv/bin/activate

Step 7. Testing the Installation

Create a simple Python script to test your installation and environment setup:

# test.py
print("Hello, Python on Linux Mint!")

Run the script:

python3 test.py

If the installation is successful, you should see the output “Hello, Python on Linux Mint!” in the terminal.

Step 8. Using the Python Interactive Shell.

Python provides an interactive shell where you can execute Python code line by line. To start the interactive shell, simply run:

python

You will see the Python prompt (>>>), indicating that you are now in the interactive mode. Try executing a few Python statements:

>>> print("Hello, Python!")
Hello, Python!
>>> x = 5
>>> y = 3
>>> print(x + y)
8

The interactive shell is a great way to test small code snippets and experiment with Python syntax.

To exit the interactive shell, type quit() or press Ctrl+D.

Congratulations! You have successfully installed Python. Thanks for using this tutorial to install the latest version of Python programming language on the Linux Mint system. For additional help or useful information, we recommend you check the official Python website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button