Ruby
官方源中的版本较低,可使用 RVM 或 rbenv 安装
RVM
RVM (Ruby Version Manager) 用来安装、管理不同的 Ruby 环境(Ruby 的不同实现、不同版本、不同的 GEM 包集)
参考 rvm 官方安装文档
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3curl -sSL https://get.rvm.io | bash -s stable# 允许 rvm 自动更新echo rvm_autoupdate_flag=2 >> ~/.rvmrc# 使用国内 Ruby 镜像echo "ruby_url=https://cache.ruby-china.org/pub/ruby" >> ~/.rvm/user/dbsource ~/.rvm/scripts/rvmrvm install 2.3.1rvm use 2.3.1 --defaultgem install bundler
注意:上述 rvm 安装步骤为单用户模式,部署 ruby 应用时使用的用户应为执行上述安装步骤的用户
rbenv
git clone https://github.com/sstephenson/rbenv.git ~/.rbenvgit clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-buildgit clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehashgit clone https://github.com/rkh/rbenv-update.git ~/.rbenv/plugins/rbenv-update# 使用 Ruby China 的镜像安装 Ruby, 国内用户推荐git clone https://github.com/AndorChen/rbenv-china-mirror.git ~/.rbenv/plugins/rbenv-china-mirrortee -a ~/.bash_profile <<-'EOF'export PATH="$HOME/.rbenv/bin:$PATH"eval "$(rbenv init -)"EOF
安装 ruby:
rbenv install 2.3.3# 默认使用版本rbenv global 2.3.3
手动编译安装
以 root 身份执行:
RUBY_VERSION=2.4.1RUBY_DOWNLOAD_MIRROR=https://cache.ruby-lang.org/pub/ruby/# RUBY_DOWNLOAD_MIRROR=https://cache.ruby-china.org/pub/ruby/yum install -y autoconf gcc gcc-c++ make automake patchyum install -y git openssh curl which tar gzip bzip2 unzip zipyum install -y openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-develyum install -y epel-release yum-utilsyum-config-manager --enable epelmkdir -p /usr/local/etcecho -e "install: --no-document\nupdate: --no-document" > /usr/local/etc/gemrcmkdir /build && cd /buildcurl -o ruby.tar.gz "$RUBY_DOWNLOAD_MIRROR/ruby-$RUBY_VERSION.tar.gz"mkdir ruby && tar -xzf ruby.tar.gz -C ruby --strip-components=1cd ruby./configure --disable-install-doc --enable-sharedmake -j"$(nproc)"make installcd / && rm -rf /build
gem update --system && gem install bundler
配置
使用Ruby China gem 源,禁止安装文档
cat <<EOF > ~/.gemrc---:backtrace: false:bulk_threshold: 1000:sources:- https://gems.ruby-china.org/:update_sources: true:verbose: truegem: "--no-user-install --no-document"EOF
