Last active
August 29, 2015 14:15
-
-
Save jmatsu/ab09e0708e4f21eb0ca5 to your computer and use it in GitHub Desktop.
Install Ruby x.y.z
This file contains hidden or 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/sh | |
# Returns TRUE if $1 doesn't exist. $1 is command name, package name, or the fragment of them. | |
check_no_cmd() | |
{ | |
# Does $PATH include $1? | |
which $1 | |
if [ $? -eq 0 ]; then | |
return 1 | |
fi | |
# Does $1 exist in installee packages via yum | |
yum list installed | grep $1 | |
if [ $? -eq 0 ]; then | |
return 1 | |
fi | |
# Not found | |
return 0 | |
} | |
# for peco, and rbenv | |
INSTALL_PKG_LIST="wget git gcc gcc-c++ openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel" | |
TO_INSTALL_PKGS="" | |
for INSTALL_PKG in $INSTALL_PKG_LIST | |
do | |
check_no_cmd ${INSTALL_PKG} && TO_INSTALL_PKGS=${TO_INSTALL_PKGS}"${INSTALL_PKG} " | |
done | |
#### SUDO!! | |
sudo yum install -y ${TO_INSTALL_PKGS} | |
# peco is very cool interactive grep cli. | |
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv | |
# snippets. plz modify followings if u would like to use /etc/profile | |
SHELL_NAME=${SHELL##*/} | |
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.${SHELL_NAME}_profile | |
echo 'eval "$(rbenv init -)"' >> ~/.${SHELL_NAME}_profile | |
source ~/.${SHELL_NAME}_profile | |
rbenv --version | |
# install ruby-build | |
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build | |
cd ~/.rbenv/plugins/ruby-build | |
sudo ./install.sh | |
cd ~/ | |
# install recent version peco | |
PECO_URL=`curl -# https://api.github.com/repos/peco/peco/releases|grep browser_download_url|grep linux|grep amd64|grep -vi rc|sed -e 's/"://g' -e 's/"//g'|awk '{print $2}'|head -1` | |
DL_PECO_FILE=${PECO_URL##*/} | |
wget PECO_URL | |
tar xvf DL_PECO_FILE | |
# peco{hogehoge}.tar.gz => peco{hogehoge} | |
TEMP_NAME=${DL_PECO_FILE%.*}; PECO_DIR_NAME=${TEMP_NAME%.*} | |
# interaction | |
TO_INSTALL_VERSION=`rbenv install --list | ${PECO_DIR_NAME}/peco` | |
echo "Accept: ${TO_INSTALL_VERSION}" | |
rbenv install -v ${TO_INSTALL_VERSION} | |
rbenv rehash | |
rbenv versions | grep ${TO_INSTALL_VERSION} | |
if [ $? -eq 0 ]; then | |
rbenv global ${TO_INSTALL_VERSION} | |
rbenv rehash | |
fi | |
ruby -v | grep ${TO_INSTALL_VERSION} | |
if [ $? -eq 0 ]; then | |
echo "Successful: Installed rbenv" | |
else | |
echo "Failure: WTF" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment