In this article, you’ll discover how to install Python 3 and pip on an Amazon EC2 instance. Whether you’re working with Amazon Linux 2 or Ubuntu, we’ve got you covered.
Python is a versatile programming language, and pip is a package manager that makes managing Python packages a breeze.
In a nutshell, to install Python and Pip on Amazon Linux 2, run sudo yum update -y
and yum install python3 -y
.
To install Python and Pip on Ubuntu on an EC2 instance, run sudo apt update
and sudo apt install python3 python3-pip -y
.
Let’s dive into the step-by-step guide to get Python 3 and pip up and running on your EC2 instance.
Table of Contents
1. Launch and Connect to Your Amazon EC2 Instance
Before you can install Python and pip, you’ll need to launch and connect to your EC2 instance.
Here’s how:
- Launch an EC2 Instance: Choose an Amazon Machine Image (AMI) based on Amazon Linux 2 or Ubuntu, depending on your preference.
- Connect to Your Instance: You can connect using the AWS Management Console or the AWS CLI. If you need assistance, refer to our previous article on securely connecting to an EC2 instance using AWS Session Manager.
1.1 Install Python 3 and pip on Amazon Linux 2
If you’re using Amazon Linux 2, follow these steps:
- Update the Package List: Run
sudo yum update -y
to ensure that all existing packages are up to date. - Install Python 3: Execute
sudo yum install python3 -y
to install Python 3. - Install pip: Python 3 on Amazon Linux 2 comes with pip, so no separate installation is needed.
1.2 Install Python 3 and pip on Ubuntu
For those using Ubuntu, the process is slightly different:
- Update the Package List: Run
sudo apt update
to update the package list. - Install Python 3: Execute
sudo apt install python3
to install Python 3. - Install pip: Run
sudo apt install python3-pip
to install pip for Python 3.
2. Check Python and Pip version
After installation, it’s a good practice to verify the versions of Python and pip:
- Check Python Version: Run
python3 --version
to display the installed Python version. - Check pip Version: Execute
pip3 --version
to display the installed pip version.
These commands will confirm that Python 3 and pip are installed correctly and ready for use.
Conclusion
Installing Python 3 and pip on an Amazon EC2 instance is a straightforward process, whether you’re using Amazon Linux 2 or Ubuntu.
By following the steps outlined in this article, you’ll have the tools you need to develop and manage Python applications on your EC2 instance.
Remember, Python is a powerful language with a rich ecosystem, and pip makes managing packages simple and efficient.