The following commands will help you to install Python 3.9.1 on a Centos 7 or Ubuntu 18.04 machine.
https://www.python.org/ftp/python/ - We'll select the latest version as of Dec 2020 (3.9.1)
sudo yum install gcc openssl-devel bzip2-devel libffi-devel
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
sudo tar zxf Python-3.9.1.tgz
cd Python-3.9.1
sudo ./configure --enable-optimizations
sudo make altinstall
sudo apt-get install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget libsqlite3-dev
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
sudo tar zxf Python-3.9.1.tgz
cd Python-3.9.1
sudo ./configure --enable-optimizations
sudo make altinstall
rm /usr/src/Python-3.9.1.tgz
touch ~/.bash_aliases
echo "alias python3='/usr/local/bin/python3.9'" >> ~/.bash_aliases
source ~/.bashrc
python3
#!/bin/bash
normal="\033[0m"
# Go here to check the list of available versions --> https://www.python.org/ftp/python/ and chage $PYTHON_VERSION to suit your needs.
PYTHON_VERSION="3.9.1"
PYTHON_PCKS=(
build-essential
zlib1g-dev
libncurses5-devlibgdbm-dev
libnss3-dev
libssl-dev
libreadline-dev
libffi-dev
wget
)
# =================================================================== # Functions # ===================================================================
INST_PACK(){
for PCKGS in "$@"; do
printf "$green_bold[INSTALLING]$normal - Packet: $red_bold$PCKGS$normal\n"
sudo apt-get -qqy --no-install-recommends install $PCKGS > /dev/null 2>&1
done
}
printf "$normal\n\n############################################################################$normal\n"
printf "$normal\t\t[BUILDING] PYTHON $PYTHON_VERSION FROM SOURCE $normal\n"
printf "$normal############################################################################$normal\n"
INST_PACK "${PYTHON_PCKS[@]}"
printf "\n"
cd /usr/src
printf "$green_bold[DOWNLOADING]$normal - Downloading:$red_bold Python $PYTHON_VERSION$normal"
sudo wget -q -nv https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz
printf "$green_bold[EXTRACTING]$normal - Extracting:$red_bold Python $PYTHON_VERSION source at: /usr/src$normal"
sudo tar zxf Python-$PYTHON_VERSION.tgz > /dev/null 2>&1
cd Python-$PYTHON_VERSION
printf "$green_bold[BUILDING]\t$normal - Building:$red_bold Python $PYTHON_VERSION (This will take some minutes)$normal"
sudo ./configure --enable-optimizations > /dev/null 2>&1
sudo make altinstall > /dev/null 2>&1
printf "$green_bold[CLEANUP]\t$normal - Cleaning:$red_bold Python $PYTHON_VERSION source files$normal"
sudo rm /usr/src/Python-$PYTHON_VERSION.tgz > /dev/null 2>&1
Thank you for that gist, really helpful!
I suggest that you also add
libsqlite3-dev
to the apt packages to be installed, otherwise the sqlite3 API is missing.