
Python is a versatile programming language used for a variety of development and scripting tasks. Pip, a package installer for Python, helps manage libraries not included in the standard Python library.
This article covers how to install Python and Pip on Ubuntu 22.04. You'll learn to install the latest Python version using a PPA, manage multiple Python versions, and use virtualenv to create isolated environments for your development projects.
Before you begin:
Have an Ubuntu 22.04 server.
Access the server using SSH as a non-root user with sudo privileges.
Python is available in the default APT repositories on Ubuntu 22.04 but may not be the latest version. To install the latest or specific Python version, you can use the deadsnakes PPA. This allows you to install custom Python versions on your server. Follow the steps below to install the latest version using the PPA.
Add the deadsnakes PPA to your server sources.
Update the server package index.
Install the latest Python version on your server.
Run the following command to install a specific version such as 3.8.
View the installed Python version on your server.
Output:
Run the following command to install Pip module.
View the installed Pip version on your server.
Output:
Access the Python Shell.
Enter the following code to test your Python installation.
Output:
Exit the Python Shell.
Python supports multiple versions on your server, and you can manage them using the update-alternatives utility. This allows you to switch between different Python versions for different project environments. Follow the steps below to install and manage multiple Python versions on your server.
Install another version of Python such as Python3.9.
Run the following update-alternatives commands to enable multiple Python versions in the /usr/bin/ location. Replace python3.10 with your active Python version and python3.9 with the newly installed version.
View all available Python versions you can switch between on your server.
Output:
Enter your desired Python version (e.g., python3.9 or python3.10) to activate in your server environment and press Enter to apply the changes. When working with virtual environments, the selected version is only activated within that specific environment.
The Python virtualenv module allows you to create isolated environments for managing dependencies in different Python projects, preventing package conflicts on your server. Follow the steps below to create and use a Python virtual environment on your server.
Install the Python virtualenv module.
Create a new sample virtual environment such as newenv.
Output:
Activate the virtual environment.
Verify that your terminal environment changes to the new Python virtual environment similar to the output below.
Run the following command to deactivate the virtual environment.
In this article, you installed Python and Pip on your Ubuntu 22.04 Vultr server, enabled multiple Python versions, and set up virtual environments for managing dependencies across different projects. For more information and usage options, please visit the Python documentation.
0 Comments
Be the first to comment and share your perspective with the community.