How to Install Python In Ubuntu Linux
Installing Python on Ubuntu is typically straightforward. Here are step-by-step instructions for installing Python on Ubuntu:
1. **Open a Terminal:**
– You can open a terminal by pressing `Ctrl + Alt + T` or by searching for “Terminal” in the application launcher.
2. **Update Package List:**
– It’s a good practice to update the package list to ensure you get the latest information about available packages. Run the following command:
“`bash
sudo apt update
“`
3. **Install Python:**
– Ubuntu usually comes with Python pre-installed. However, you might want to install a specific version or ensure that you have the latest version. The following command will install Python 3:
“`bash
sudo apt install python3
“`
If you specifically want Python 2 (though Python 2 is officially deprecated and not recommended for new projects), you can use:
“`bash
sudo apt install python
“`
4. **Verify Installation:**
– After the installation is complete, you can check the installed Python version by running:
“`bash
python3 –version
“`
or for Python 2:
“`bash
python –version
“`
This should display the installed Python version.
5. **Install pip (Python Package Manager):**
– Pip is a package manager for Python that allows you to install additional packages. Install it by running:
“`bash
sudo apt install python3-pip
“`
After installation, you can check the installed pip version using:
“`bash
pip3 –version
“`
6. **Optional: Install Virtual Environment (Recommended for Development):**
– Using virtual environments is a good practice for isolating project dependencies. Install the `venv` module with:
“`bash
sudo apt install python3-venv
“`
Then, you can create a virtual environment for your project:
“`bash
python3 -m venv myenv
“`
Activate the virtual environment:
“`bash
source myenv/bin/activate
“`
You’ll see the virtual environment’s name in your terminal prompt, indicating that you are working within the virtual environment.
That’s it! You have successfully installed Python on Ubuntu. Adjust the version numbers as needed based on your specific requirements.
ubuntu