Ruby and Rbenv - ThuyNT13/my_setup GitHub Wiki

Install rbenv

navigate to Home

cd

install required dependencies for rbenv and Ruby:

sudo apt-get install autoconf zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

Clone rbenv repo:

git clone git://github.com/sstephenson/rbenv.git .rbenv

setup $PATH so that system can find rbenv:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

alternatively, go into .bashrc or .bash_profile and insert code (possibly needs to be in both):

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

source rbenv:

source ~/.bash_profile

Check to make sure rbenv was installed correctly:

type rbenv

Should output:

rbenv is a function
rbenv () 
{ 
    local command;
    command="$1";
    if [ "$#" -gt 0 ]; then
        shift;
    fi;
    case "$command" in 
        rehash | shell)
            eval "$(rbenv "sh-$command" "$@")"
        ;;
        *)
            command rbenv "$command" "$@"
        ;;
    esac
}

Install ruby-build plugin, to simplify installation process for new Ruby versions with utilization of rbenv install command.

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile

Install Ruby

see list of versions:

rbenv install -l

Install specified version of ruby (2.3.0)

rbenv install -v 2.3.0

set default version:

rbenv global 2.3.0

check to make sure Ruby was installed

ruby -v

Installing Gems

Turns off local documentation for each gem, making installation process less lengthy.

echo "gem: --no-document" > ~/.gemrc

Install gem bundler to manage application dependencies, rails and rspec

gem install bundler
gem install rails
gem install rspec

rbenv users need to run rbenv rehash after installing gems, reloading the Ruby environment allowing for changes to take place.