TL;DR
To install Python 3 on Ubuntu, you can follow these steps:
- Open the Terminal by pressing
Ctrl + Alt + T. - Run the command
sudo apt updateto update the package lists. - Run the command
sudo apt upgradeto upgrade the installed packages. - Install Python 3 by running
sudo apt install python3in the Terminal. - Verify the installation by running the
python3 --versionto see the Python version installed on your system.
Configuring Python 3 on Ubuntu is crucial for optimal usage. Setting up environment variables and installing Python packages. addressing common installation errors, including python3 command not found, dependency issues, permission denied, incorrect Python version, and environment variable setup.
Explore the guide below for a step-by-step guide on how to install Python 3, configure it, and common errors with possible solutions.
Python, a powerful and versatile programming language, is widely used in various industries, from web development and data analysis to artificial intelligence and scientific research. With its clean syntax and extensive library support, Python 3 has gained immense popularity across various domains, from web development to data science and machine learning. If you’re an aspiring Python developer or a seasoned programmer, having Python 3 installed on your Ubuntu system is crucial. In this comprehensive guide, I will walk you through the step-by-step process to Python 3 on Ubuntu, configuring it, and common errors with possible solutions.
How to Install Python 3 on Ubuntu
To install Python 3 on Ubuntu, you’ll need a compatible version of Ubuntu (such as 22.04 LTS), sufficient free disk space, at least 1 GB of RAM, a modern x86-based processor, and an active internet connection for downloading and updating Python, and its libraries. Follow these steps:
- Open the Terminal by pressing
Ctrl + Alt + T.

- Run the following command to update the package:
<strong>sudo apt update</strong> - This command will update the package lists for upgrades and new package installations.

- After the update process completes, run the following command to upgrade:
<strong>sudo apt upgrade</strong> - The command will upgrade the installed packages.

- Ubuntu provides Python 3 through its official repository. For installation, open the Terminal and execute the following command to install Python 3 on Ubuntu:
<strong>sudo apt install python3</strong> - After the execution of the command, Python 3 will be installed along with the required dependencies.

- To check Python 3 is correctly installed on your system, run the following command:
<strong>python3 --version</strong> - If the installation was successful, the Terminal will display the Python version installed on your system.

How to Configure Python 3 on Ubuntu
Configuring Python 3 on Ubuntu is essential for ensuring optimal usage and leveraging its benefits. This section will cover two crucial aspects: setting up environment variables and installing Python packages and libraries. You can customize your Python environment and enhance its functionality by following the steps below.
1. Setting Up Environment Variables
To ensure Python functions properly on Ubuntu, you need to configure the environment variables. This allows for seamless execution and accessibility. Follow these steps to set up environment variables:
- Open the Terminal.
- Execute the following command to open the .bashrc file in a text editor:
<strong>nano ~/.bashrc</strong> 
- Scroll to the bottom of the file and add the following lines:
<strong>export PATH="/usr/local/bin:$PATH"</strong>
<strong>export PATH="/usr/local/sbin:$PATH"</strong> - It will set the environment variables for the proper functioning of python.

- Save the changes by pressing
Ctrl + Oand exit the text editor by pressingCtrl + X.

- To apply the changes, run the following command:
<strong>source ~/.bashrc</strong> 
2. Installing Python Packages and Libraries
Python packages and libraries expand the capabilities of the language. With these libraries, you can supercharge your Python projects and tap into a vast array of functionality. To install additional packages using pip, the package installer for Python, follow these steps:
- Launch the Terminal window and run the following command to install pip:
<strong>sudo apt install python3-pip</strong> - Once pip is installed, you can use it to install Python packages.

- To install the python packages, run the following command: