How to Install Python on Ubuntu (Step-by-Step Guide)

Linux Simplify will guide you through how to install Python on Ubuntu in a clear and practical way. If you are new to Linux or just starting with Python development, Ubuntu is one of the best environments you can use. Python already comes pre-installed on most Ubuntu systems, which makes the setup process easier than many people expect.

Even though Ubuntu includes Python by default, there are situations where you may need to install a newer version, install additional tools, or prepare a proper development environment. This is especially important if you are working on modern Python projects or following the latest Python releases.

How to Install Python on Ubuntu Terminal

In this guide, you will learn how to check your current Python installation, install Python using different methods, and set up a clean Python development environment on Ubuntu. All steps are explained in a simple and structured way so you can follow along without confusion.

Check and Prepare Your Ubuntu System

Before installing anything, it is important to check whether Python is already installed on your Ubuntu system. Most Ubuntu versions come with Python 3 by default.

Open a terminal and run the following command:

Check and Prepare Your Ubuntu System on Command
python3 --version

If Python is installed, you will see output similar to Python 3.12.3. You can also check whether Python 2 exists on your system, although it is no longer recommended:

python2 --version

Next, update your system packages to avoid dependency issues during installation.

sudo apt update

After that, upgrade existing packages:

sudo apt -y upgrade

Do not remove the default system Python package, as Ubuntu depends on it for internal tools. Removing it can break the system.

How to Install Python on Ubuntu (Step-by-Step Guide)


For convenience, you can make the python command point to Python 3:

sudo apt install python-is-python3

Install Python on Ubuntu Using Different Methods

Ubuntu provides several ways to install Python depending on your needs. You can choose the method that best fits your workflow.

Install Python Using APT

This is the simplest and safest method for most users.


sudo apt install python3-full

This command installs Python along with standard libraries, pip, and virtual environment support.

Install Newer Python Versions Using Deadsnakes PPA

If you need a newer Python version than what is available in the default repository, you can use the Deadsnakes PPA.


sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12

This method is commonly used by developers who need specific Python versions.

Build Python from Source (Advanced)

For advanced users who want maximum control, Python can be built from source.

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev \
libnss3-dev libssl-dev libreadline-dev libffi-dev wget
wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz
tar -xf Python-3.12.1.tgz
cd Python-3.12.1
./configure --enable-optimizations
sudo make altinstall

Using altinstall ensures that the system Python is not overwritten.

Set Up Your Python Development Environment

After installing Python, the next step is preparing a proper development environment.

Install pip if it is not already available:

sudo apt install python3-pip python3-pip-whl

Ubuntu strongly recommends using virtual environments to keep project dependencies isolated.

sudo apt install python3-venv

Create a project directory and virtual environment:

mkdir project_name
cd project_name
python3 -m venv .venv

Activate the virtual environment:

source .venv/bin/activate

Once activated, you can install packages safely:

pip install package_name

To exit the virtual environment, simply run:

deactivate

Conclusion

Installing Python on Ubuntu is much easier than many users expect. Ubuntu already provides a solid Python foundation, and with a few additional steps, you can tailor your setup to match your development needs.

By checking your existing installation, choosing the right installation method, and using virtual environments, you can create a clean and reliable Python workflow.

Whether you are a beginner or an experienced developer, Ubuntu offers a stable and developer-friendly platform for Python development. Once your environment is ready, you can focus on writing Python code and building real-world projects.

Post a Comment for "How to Install Python on Ubuntu (Step-by-Step Guide)"