
Python is a modern general-purpose programming language suitable for various development and scripting tasks. Pip is a package installer for Python that allows you to install and manage additional libraries that are not part of the standard Python library on a server.
This article explains how to install Python and Pip on an Ubuntu 24.04 server, along with managing application processes on your server. You will learn how to install Python on Ubuntu 24.04 using a PPA to get the latest version, manage multiple Python versions, and use the Python virtual environment package, virtualenv, to create isolated development environments.
Before you begin:
Deploy an Ubuntu 24.04 server instance on Vultr.
Access the server using SSH as a non-root user with sudo privileges.
Python is available in the default APT repositories on Ubuntu 24.04 but may not be the latest version. Personal Package Archives (PPAs) enable the installation of custom application packages on a server, and you can use the deadsnakes PPA to install the latest or specific Python version on your server. Follow the steps below to install the latest Python 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.10.
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 you can install and use on your server using the update-alternatives utilities. This enables you to work with multiple project environments that match specific Python requirements on your server. Follow the steps below to install multiple Python versions for use on your server.
Install another version of Python such as Python3.9.
Run the following update-alternatives commands to enable multiple versions in your Python binary /usr/bin/ location. Replace python3.12 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 to activate in your server environment and press Enter to apply changes. When working with virtual environments, the selected version is only activated in your environment.
The Python virtual environment module virtualenv creates virtual environments that enable the management of dependencies for different Python projects to limit package conflicts on your server. Follow the steps below to create a Python virtual environment to use 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.
You have installed Python and Pip on your Ubuntu 24.04 Vultr server. Then, you enabled multiple versions and set up virtual environments to use Python with different projects on your server. 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.