Skip to content

Instantly share code, notes, and snippets.

@dceoy
Last active May 7, 2019 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dceoy/c1ef8c967b898f69071a5ea56ac04f80 to your computer and use it in GitHub Desktop.
Save dceoy/c1ef8c967b898f69071a5ea56ac04f80 to your computer and use it in GitHub Desktop.
[Shell] Install the latest version of Python with pyenv
#!/usr/bin/env bash
#
# https://github.com/dceoy/ansible-dev/blob/master/roles/python/files/install_pyenv.sh
set -uex
PYENV_DIR="${HOME}/.pyenv"
PYENV="${PYENV_DIR}/bin/pyenv"
[[ ${#} -ge 1 ]] && PY_MAJOR_VER="${1}" || PY_MAJOR_VER=3
if [[ -d "${PYENV_DIR}" ]]; then
cd "${PYENV_DIR}" && git pull && cd -
else
git clone https://github.com/yyuu/pyenv.git "${PYENV_DIR}"
fi
PY_LATEST_VER=$(
${PYENV} install --list \
| awk "\$1 ~ /^${PY_MAJOR_VER}[\.\-0-9]*$/ { v=\$1 } END { print v }"
)
if [[ -z "${PY_LATEST_VER}" ]]; then
echo 'version not found' && exit 1
elif [[ -f "${PYENV_DIR}/versions/${PY_LATEST_VER}/bin/python" ]]; then
:
else
${PYENV} install "${PY_LATEST_VER}" && ${PYENV} global "${PY_LATEST_VER}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment