Python is a popular, high-level, and versatile programming language that can be utilized for various purposes such as web development, data analysis, artificial intelligence, and more. If you’re using Oracle Linux, you might want to install Python to leverage its capabilities. In this tutorial, we’ll guide you through the process of how to install Python on Oracle Linux.
Table of Contents
- Prerequisites
- Installing Python using YUM
- Installing Python from Source
- Verify Python Installation
- Setting up a Virtual Environment
- Conclusion
Prerequisites
Before you begin, ensure that you have:
- Oracle Linux 7 or 8 installed on your system
- Root or sudo access to execute commands
If you need help with other Oracle Linux installations, check out these guides:
- How to install Nginx on Oracle Linux
- How to install Apache on Oracle Linux
- How to install CWP on Oracle Linux
How to Install Python on Oracle Linux
Installing Python using YUM
Oracle Linux uses YUM (Yellowdog Updater, Modified) as the package manager. To install Python using YUM, follow these steps:
- Update your system packages:
sudo yum update
- Install the EPEL repository:
sudo yum install epel-release
- Install Python:
sudo yum install python3
This command installs the latest available version of Python 3 from the EPEL repository.
Installing Python from Source
If you want to install a specific version of Python or prefer to compile it from source, follow these steps:
- Update your system packages:
sudo yum update
- Install required dependencies:
sudo yum groupinstall "Development Tools"
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
- Download the desired Python version from the official website:
wget https://www.python.org/ftp/python/3.x.y/Python-3.x.y.tar.xz
Replace 3.x.y
with the desired version number, for example, 3.9.7
.
- Extract the downloaded archive:
tar xvf Python-3.x.y.tar.xz
- Change to the extracted directory:
cd Python-3.x.y
- Configure the build:
./configure --enable-optimizations
- Compile and install Python:
make
sudo make altinstall
Using altinstall
instead of install
prevents the new Python installation from conflicting with the system’s default Python.
Verify Python Installation
To verify that Python is installed correctly, run the following command:
python3 --version
This command should output the installed Python version.
Setting up a Virtual Environment
Using a virtual environment is a best practice for Python development, as it allows you to isolate project dependencies. To set up a virtual environment, follow these steps:
- Install the
python3-venv
package:
sudo yum install python3-venv
- Create a new directory for your project:
mkdir my_project
cd my_project
- Create a virtual environment within the project directory:
python3 -m venv venv
This command creates a new virtual environment named venv
in the my_project
directory.
- Activate the virtual environment:
source venv/bin/activate
After activating the virtual environment, your command prompt should change to indicate that the virtual environment is active.
- Install packages within the virtual environment:
pip install package_name
Replace package_name
with the desired package to install, for example, numpy
or django
.
- Deactivate the virtual environment when you’re done:
deactivate
Deactivating the virtual environment returns you to the system’s default Python environment.
Conclusion
You have successfully installed Python on your Oracle Linux system and set up a virtual environment for your Python projects. Python is a powerful language with many applications, and having it installed on your Oracle Linux system will enable you to develop a wide variety of projects.
For more Oracle Linux tutorials and guides, check out the following articles: