Skip to content

Instantly share code, notes, and snippets.

@AvnerCohen
Last active October 25, 2018 10:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AvnerCohen/3e5cbe09bc40231869578ce7cbcbe9cc to your computer and use it in GitHub Desktop.
Save AvnerCohen/3e5cbe09bc40231869578ce7cbcbe9cc to your computer and use it in GitHub Desktop.
Updated Python 2.7.xx on an Amazon AMI + make it default (in alternatives) and symlik pip ad virtualenv for future usage
#!/usr/bin/env bash
NEW_VERSION="2.7.14"
CURRENT_VERSION="$(python -V 2>&1)"
if [[ "$CURRENT_VERSION" == "Python $NEW_VERSION" ]]; then
echo "Python $NEW_VERSION already installed, aborting."
else
echo "Starting upgrade from ${CURRENT_VERSION} to ${NEW_VERSION}"
if [ ! -d "python_update" ]; then
mkdir python_update
cd python_update
wget https://www.python.org/ftp/python/$NEW_VERSION/Python-$NEW_VERSION.tgz
tar xfz Python-$NEW_VERSION.tgz
cd Python-$NEW_VERSION/
else
cd python_update
cd Python-$NEW_VERSION/
fi
./configure --enable-loadable-sqlite-extensions --prefix /usr/local/lib/python$NEW_VERSION --enable-ipv6 --enable-unicode=ucs4 --enable-shared
make && make install
alternatives --install /usr/bin/python python /usr/local/lib/python$NEW_VERSION/bin/python2.7 $(echo $NEW_VERSION | sed 's/\.//g')0
update-alternatives --refresh python
update-alternatives --auto python
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python
ln -sf /usr/local/lib/python$NEW_VERSION/bin/pip /usr/bin/pip
pip install -U virtualenv
ln -sf /usr/local/lib/python$NEW_VERSION/bin/virtualenv /usr/bin/virtualenv
echo "DONE!"
fi
@slallum
Copy link

slallum commented Jul 13, 2017

Like the retry for get-pip 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment