#!/bin/bash ######################################## # install latest python version # into /usr/bin/ # with all neccessary packages ######################################## def_version="3.11.1" py_dir="python_installation" sudo yum update -y sudo yum upgrade -y sudo yum remove openssl-devel -y sudo yum -y groupinstall "Development Tools" sudo yum -y install gcc openssl11 openssl11-devel bzip2-devel libffi-devel py_check(){ version=${1:-$1} local version_check=$(python${version::-2} -V 2>&1 | grep -Po '(?<=Python )(.+)') echo $version_check ! [ -z $version_check ] } install_py() { mkdir $py_dir && cd $py_dir wget -v https://www.python.org/ftp/python/$version/Python-$version.tgz tar xzf Python-$version.tgz #v rm -f Python-$version.tgz cd Python-$version ./configure --enable-optimizations --with-ensurepip=install make -j $(nproc) sudo make altinstall # cleanup cd ../.. rm -rf $py_dir echo "Python-$version is installed. Enjoy ;)" } echo "#################### ####################" read -t 10 -p "Enter Python version you wish to install [default $def_version] If no value entered within 10 seconds window, default value is used: " version # check if Python is already installed if [[ -z $version ]] then #checking default version echo "Checking if default Python $def_version is installed..." if py_check $def_version; then echo "Python-$version is alredy installed" else echo "Installing Python-$version..." install_py $version fi else # checking non default version echo "Checking if entered Python $version is installed..." if py_check $version; then echo "Python-$version is alredy installed" else echo "Installing Python-$version..." install_py $version fi fi echo "#################### The End ####################"