Last active
June 30, 2017 02:54
-
-
Save brysontyrrell/4497718b6561085c528a80866be681c7 to your computer and use it in GitHub Desktop.
Install Python from source on Ubuntu Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script will install specific versions of Python on Ubuntu Linux servers | |
if [ "$(whoami)" != "root" ]; then | |
echo "WARNING: You must run this script as 'root'" | |
# This shortcut method will fail if the script file does not have execute permissions | |
exec sudo -- "$0" "$@" | |
fi | |
inputVersion=$1 | |
if [[ $inputVersion == "" ]]; then | |
echo "You must input a supported version (e.g. 2.7.11, 3.5.1)" | |
exit 1 | |
fi | |
exitOnError() { | |
error=$1 | |
lineno=$2 | |
echo "The previous command resulted in a fatal error: ${error}, line: ${lineno}" | |
exit $error | |
} | |
trap 'exitOnError ${?} ${LINENO}' ERR | |
setNameAndURL() { | |
pythonName="Python-${inputVersion}" | |
pythonURL="https://www.python.org/ftp/python/${inputVersion}/Python-${inputVersion}.tgz" | |
} | |
pythonDependencies() { | |
/usr/bin/apt-get update -q | |
/usr/bin/apt-get install build-essential checkinstall -qqy || exitOnError $? | |
/usr/bin/apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev -qqy | |
} | |
installPip() { | |
/usr/bin/apt-get install build-essential python-dev python-pip -qqy || exitOnError $? | |
/usr/bin/pip install virtualenv || exitOnError $? | |
} | |
download() { | |
cd /usr/src | |
/usr/bin/curl ${pythonURL} -O -f || exitOnError $? | |
/bin/tar xzf ${pythonName}.tgz || exitOnError $? | |
} | |
makePython() { | |
cd /usr/src/${pythonName} | |
./configure | |
make | |
make install | |
} | |
main() { | |
pythonDependencies | |
setNameAndURL | |
download | |
makePython | |
installPip | |
exit 0 | |
} | |
main |
Indeed it is. Not sure what I was doing there.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the checkVersion function is missing in this script!!!!