Ruby

官方源中的版本较低,可使用 RVM 或 rbenv 安装

RVM

RVM (Ruby Version Manager) 用来安装、管理不同的 Ruby 环境(Ruby 的不同实现、不同版本、不同的 GEM 包集)

参考 rvm 官方安装文档

  1. gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
  2. curl -sSL https://get.rvm.io | bash -s stable
  3. # 允许 rvm 自动更新
  4. echo rvm_autoupdate_flag=2 >> ~/.rvmrc
  5. # 使用国内 Ruby 镜像
  6. echo "ruby_url=https://cache.ruby-china.org/pub/ruby" >> ~/.rvm/user/db
  7. source ~/.rvm/scripts/rvm
  8. rvm install 2.3.1
  9. rvm use 2.3.1 --default
  10. gem install bundler

注意:上述 rvm 安装步骤为单用户模式,部署 ruby 应用时使用的用户应为执行上述安装步骤的用户

rbenv

  1. git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
  2. git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
  3. git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
  4. git clone https://github.com/rkh/rbenv-update.git ~/.rbenv/plugins/rbenv-update
  5. # 使用 Ruby China 的镜像安装 Ruby, 国内用户推荐
  6. git clone https://github.com/AndorChen/rbenv-china-mirror.git ~/.rbenv/plugins/rbenv-china-mirror
  7. tee -a ~/.bash_profile <<-'EOF'
  8. export PATH="$HOME/.rbenv/bin:$PATH"
  9. eval "$(rbenv init -)"
  10. EOF

安装 ruby:

  1. rbenv install 2.3.3
  2. # 默认使用版本
  3. rbenv global 2.3.3

手动编译安装

以 root 身份执行:

  1. RUBY_VERSION=2.4.1
  2. RUBY_DOWNLOAD_MIRROR=https://cache.ruby-lang.org/pub/ruby/
  3. # RUBY_DOWNLOAD_MIRROR=https://cache.ruby-china.org/pub/ruby/
  4. yum install -y autoconf gcc gcc-c++ make automake patch
  5. yum install -y git openssh curl which tar gzip bzip2 unzip zip
  6. yum install -y openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel
  7. yum install -y epel-release yum-utils
  8. yum-config-manager --enable epel
  9. mkdir -p /usr/local/etc
  10. echo -e "install: --no-document\nupdate: --no-document" > /usr/local/etc/gemrc
  11. mkdir /build && cd /build
  12. curl -o ruby.tar.gz "$RUBY_DOWNLOAD_MIRROR/ruby-$RUBY_VERSION.tar.gz"
  13. mkdir ruby && tar -xzf ruby.tar.gz -C ruby --strip-components=1
  14. cd ruby
  15. ./configure --disable-install-doc --enable-shared
  16. make -j"$(nproc)"
  17. make install
  18. cd / && rm -rf /build
  1. gem update --system && gem install bundler

配置

使用Ruby China gem 源,禁止安装文档

  1. cat <<EOF > ~/.gemrc
  2. ---
  3. :backtrace: false
  4. :bulk_threshold: 1000
  5. :sources:
  6. - https://gems.ruby-china.org/
  7. :update_sources: true
  8. :verbose: true
  9. gem: "--no-user-install --no-document"
  10. EOF

参考资料