Last active
May 7, 2019 10:11
-
-
Save dceoy/a99fb89eec4b95c68f1e0991af0f9f16 to your computer and use it in GitHub Desktop.
[Shell] Install the latest version of Ruby with rbenv
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
#!/usr/bin/env bash | |
# | |
# https://github.com/dceoy/ansible-dev/blob/master/roles/ruby/files/install_rbenv.sh | |
set -uex | |
RBENV_DIR="${HOME}/.rbenv" | |
RB_BUILD_DIR="${HOME}/.rbenv/plugins/ruby-build" | |
RBENV="${RBENV_DIR}/bin/rbenv" | |
[[ ${#} -ge 1 ]] && RB_MAJOR_VER="${1}" || RB_MAJOR_VER=2 | |
if [[ -d "${RBENV_DIR}" ]]; then | |
cd "${RBENV_DIR}" && git pull && cd - | |
cd "${RB_BUILD_DIR}" && git pull && cd - | |
else | |
git clone https://github.com/rbenv/rbenv.git "${RBENV_DIR}" | |
git clone https://github.com/rbenv/ruby-build.git "${RB_BUILD_DIR}" | |
fi | |
RB_LATEST_VER=$( | |
${RBENV} install --list \ | |
| awk "\$1 ~ /^${RB_MAJOR_VER}[\.\-0-9]*$/ { v=\$1 } END { print v }" | |
) | |
if [[ -z "${RB_LATEST_VER}" ]]; then | |
echo 'version not found' && exit 1 | |
elif [[ -f "${RBENV_DIR}/versions/${RB_LATEST_VER}/bin/ruby" ]]; then | |
: | |
else | |
${RBENV} install "${RB_LATEST_VER}" && ${RBENV} global "${RB_LATEST_VER}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment