Centos6/Centos7

安装rbenv

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
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
exec $SHELL

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

安装Ruby

# 安装指定版本的Ruby
rbenv install -v 2.6.0

# 使用指定版本的Ruby
rbenv global 2.6.0

# 如果用命令行ssh登录,可能需要重新连接一下才能看到版本的变化
ruby -v

然后安装bundler gem来管理依赖

gem install bundler

如果不想再gem install的时候为每个安装的依赖生成一份文档,可以用下面的命令:

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

查看Centos版本的方法

cat /etc/redhat-release

参考

  • https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-centos-7