shell script to install python on linux

Following script used to install Python V 3.7 on Linux…can be used on OSX also.


# !/bin/bash

# exit on error

set -e

SUDO='' if (( $EUID != 0 )); then SUDO='sudo' fi

MAJOR_VERSION=3.7
MINOR_VERSION=3.7.0

# needs to be run with elevated privileges (sudo)

$SUDO /usr/bin/apt-get install build-essential checkinstall
$SUDO /usr/bin/apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

cd /usr/src

$SUDO wget "https://www.python.org/ftp/python/$MINOR_VERSION/Python-$MINOR_VERSION.tgz"

$SUDO tar xzf Python-$MINOR_VERSION.tgz

cd Python-$MINOR_VERSION $SUDO ./configure --enable-optimizations
$SUDO make altinstall

echo "Installation complete...checking versions"
echo python $MAJOR_VERSION -V

echo pip $MAJOR_VERSION -V