Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CentOS: rbenv install and system wide install
#!/bin/bash
# CentOS rbenv system wide installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv system wide on CentOS 5/6, also allows single user installs.
# Install pre-requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel \
make bzip2 autoconf automake libtool bison iconv-devel git-core
# Check if Git is installed
hash git 2>&- || {
echo >&2 "Error: Git not found. Hint: Try installing the RPMForge or EPEL package repository.";
exit 1;
}
# Check if /usr/local/rbenv already exists
if [[ -d "/usr/local/rbenv" ]]; then
echo >&2 "Error: /usr/local/rbenv already exists. Aborting installation.";
exit 1;
fi
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Check if clone succesful
if [ $? -gt 0 ]; then
echo >&2 "Error: Git clone error! See above.";
exit 1;
fi
# Add rbenv to the path
echo '# rbenv setup - only add RBENV PATH variables if no single user install found' > /etc/profile.d/rbenv.sh
echo 'if [[ ! -d "${HOME}/.rbenv" ]]; then' >> /etc/profile.d/rbenv.sh
echo ' export RBENV_ROOT=/usr/local/rbenv' >> /etc/profile.d/rbenv.sh
echo ' export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh
echo ' eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh
echo 'fi' >> /etc/profile.d/rbenv.sh
chmod +x /etc/profile.d/rbenv.sh
# Install ruby-build:
pushd /tmp
rm -rf /tmp/ruby-build
git clone git://github.com/sstephenson/ruby-build.git
# Check if clone succesful
if [ $? -gt 0 ]; then
echo >&2 "Error: Git clone error! See above.";
exit 1;
fi
cd ruby-build
./install.sh
popd
echo '---------------------------------'
echo ' rbenv installed system wide to /usr/local/rbenv'
echo ' Remember to restart your shell for the changes to take effect!'
echo '---------------------------------'
#!/bin/bash
# CentOS rbenv installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv to user home on CentOS 5/6.
if [[ -d "${HOME}/.rbenv" ]]; then
echo >&2 "Error: ${HOME}/.rbenv already exists. Aborting installation.";
exit 1;
fi
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
# Add rbenv to the path
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
echo '---------------------------------'
echo " rbenv installed to $HOME/.rbenv"
echo ' Remember to restart your shell for the changes to take effect!'
echo '---------------------------------'
@KazW

This comment has been minimized.

Copy link

@KazW KazW commented Apr 19, 2012

I'm not sure, but I think you meant psiconv-devel, because no package named iconv-devel is in epel or the standard repos.

@viniciuscb

This comment has been minimized.

Copy link

@viniciuscb viniciuscb commented Feb 21, 2013

Thank you so much!

@tomfast

This comment has been minimized.

Copy link

@tomfast tomfast commented Apr 3, 2013

Thanks! I had to add

export PATH=$PATH:/usr/local/bin

just before installing rubies.

@tnolet

This comment has been minimized.

Copy link

@tnolet tnolet commented Nov 6, 2013

awesome. Saved me a million hassles with RVM

@baibaluo

This comment has been minimized.

Copy link

@baibaluo baibaluo commented Jan 3, 2014

Thanks!
it worked perfectly in Centos 6.2

default, only root can gem install xxx, but it's good enough for me.

@devops-senpai

This comment has been minimized.

Copy link

@devops-senpai devops-senpai commented Mar 9, 2014

Why not add source ~/.bash_profile to the end of the script? or also just run the export and eval?

@jalcine

This comment has been minimized.

Copy link

@jalcine jalcine commented May 10, 2014

@sigull for the second one; that'd make sense. I think for the other one; you'd have to restart the shell since source ~/.bash_profile wouldn't invoke a full reload.

@felideon

This comment has been minimized.

Copy link

@felideon felideon commented Sep 23, 2014

Sorry, how do you run this script without sprinkling sudo all over the place? Isn't /usr/local usually owned by root?

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Mar 15, 2015

sudo -v = problem solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.