Install Ruby on Rails with Rbenv on CentOS 7

1.First, you need to install dependencies for rbenv and Ruby:

sudo yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel

2.Install rbenv and ruby-build, be sure that you are in your non-root sudo user’s home directory:

cd ~
git clone git:// .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
git clone git:// ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

3.You need to determine the version of Ruby that you need. You can list available Ruby versions for installation with the following command:

rbenv install -l

4.Here, I will install the latest stable version, Ruby 2.2.3:

rbenv install -v 2.2.3
rbenv rehash

5.If you want to use another version, just install the version as above:

rbenv install -v 2.2.0
rbenv rehash

6.You can check all the versions you have installed with:

rbenv versions

The version with * is the active version
7.So, at the very least, you need to set your favorite version as global version for daily use:

rbenv global 2.2.3

8.Verify your choice with:

ruby -v

9.Also, you need to install the bundler gem to manage your application dependencies:

gem install bundler

10.Install the latest version of Rails:

gem install rails
rbenv rehash

gem install rails -v 版本号
gem uninstall rails -v 版本号

11.Check if Rails is installed properly:

rails -v