Skip to content

Instantly share code, notes, and snippets.

@BTabaku
Created November 4, 2023 21:54
Show Gist options
  • Save BTabaku/e79ac24475f6ee6629e90d1abd0acaa2 to your computer and use it in GitHub Desktop.
Save BTabaku/e79ac24475f6ee6629e90d1abd0acaa2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to install Python 3.9 on CentOS 7
# Please run it as a root
# Install development tools and libraries
yum groupinstall -y "Development Tools"
yum install -y openssl-devel bzip2-devel libffi-devel
# Download Python 3.9 source code
cd /usr/src
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
# Extract the source code tarball
tar xzf Python-3.9.0.tgz
# Compile and install Python 3.9
cd Python-3.9.0
./configure --enable-optimizations --prefix=/usr/local
make altinstall
# Add /usr/local/bin to PATH in .bashrc for future sessions
if ! grep -q "/usr/local/bin" /etc/profile; then
echo "export PATH=/usr/local/bin:\$PATH" >> /etc/profile
fi
# Refresh environment variables
source /etc/profile
# Verify Python 3.9 installation
python3.9 -V
# Clean up the tarball
rm /usr/src/Python-3.9.0.tgz
echo "Python 3.9 installation is complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment