Or copy link
Copy link
Python is a powerful and versatile programming language favored by beginner and intermediate developers. Its simplicity, extensive libraries, and vast community resources make it an ideal choice for various projects, from web development and data science to automation and machine learning. Python makes it an excellent language for anyone interested in coding. Python can be installed in Windows systems or Linux distributions.
In this post, we provide a comprehensive guide to installing Python on Ubuntu, a Linux operating system. This post is a gateway for those developers who start their programming journey.
Before proceeding with the installation, check if Python is already on your Ubuntu system. Open the terminal from above and type the following command:
python --version
If Python is installed, the terminal will display the installed version number. If you receive a “command not found” error message, Python needs to be installed.
Installing Python 3
Python 3 is the current stable release of Python programming language. For this post, we will use Python 3 as the default. There are three primary methods for installing Python 3 on Ubuntu:
This is the recommended method for most users. APT provides a simple smooth and convenient way to install and manage software packages, including Python. For this open the terminal and type the following command:
sudo apt install python3
The sudo command grants administrative privileges for the installation. Enter your password when prompted. The system will download and install Python 3.
This method allows you to install specific Python versions, including newer ones. It involves adding a Personal Package Archive (PPA) provided by the Deadsnakes project. For this add the repository with the following command in the terminal:
sudo add-apt-repository ppa:deadsnakes/ppa
After adding the repository, Update the package with the following command:
sudo apt update
After the update, you can install Python 3 along with your desired version. For example, if you want to use the 3.11 version you can type the following command:
sudo apt install python3.11
You can install Python by visiting its official website and downloading its binary for Ubuntu. You can find the latest version by downloading the compressed file for Ubuntu. After downloading place the folder in the directory and access them from the terminal.
cd ~/ sudo ./configure make make test
After building the essentials, Use the APT command to install Python.
Verifying the Installation:
Once the installation is complete, verify it by checking the version again. The terminal should display the installed Python version.
Experience the power of Ubuntu VPS
Get the reliability of the world’s most popular Linux distro and the flexibility of a virtual server. Enjoy blazing-fast speeds and low latency.
While Python is now installed, it’s recommended to create a virtual environment for your projects. This isolates your project’s dependencies from the system’s Python environment, preventing conflicts and ensuring clean installations. To create a virtual environment, run the following command:
python3 -m venv my_venv
This creates a virtual environment named my_venv. To activate it, type:
source my_venv/bin/activate
Your terminal prompt will now indicate the active virtual environment. To deactivate it, type:
deactivate
Writing Your First Python Program
Now that Python is installed and your environment is set up, you can write your first Python program! Open a text editor and create a file named hello.py. Inside the file, write the following code:
print("Hello, World!")
Save the file and open a terminal window. Navigate to the directory containing the file and run the following command:
python3 hello.py
You should see the message “Hello, World!” displayed on your screen. Congratulations, you’ve successfully written and run your first Python program!
Python comes with a built-in package manager called PIP for installing and managing third-party libraries. Install PIP by running the following command:
sudo apt install python3-pip
If you want to set Python 3.11 as the default type the following command:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
You can also run Python directly from any directory. For this, Add the path to your Python installation directory to the PATH environment variable.
Modifying your shell configuration file
export PATH="$PATH:/path/to/python/bin"
Replace /path/to/python/bin with the actual path to your Python installation’s bin directory. For example, if you have Python 3.11 installed, this path might be /usr/bin/python3.11/bin.
source ~/.bashrc
Installing Python on Ubuntu is a straightforward process. By following the steps outlined in this article, you can be up and running with this powerful and versatile programming language in no time. You can explore the various resources available online to enhance your learning and start building projects.
You can install Python on the Linux system. For this, you need a powerful platform to host your Python projects Look no further than Ultahost’s Linux VPS hosting! Our VPS plans offers ensure fast loading times for your applications and easily upgrade your resources as your needs grow. Get started today and enjoy the freedom and flexibility of a VPS!
Rust, a systems programming language, has gained popula...
When you are a Linux user, few tools commands are as po...
Terraform, developed by HashiCorp, is an open-source in...
In Ubuntu 22.04, UFW stands for Uncomplicated Firewall....
Apache is a free and open-source web server the most po...
Node.js is a runtime environment that enables the execu...
Save my name, email, and website in this browser for the next time I comment.
Δ