kawabatas技術ブログ

試してみたことを書いていきます

Ubuntu 16.04 LTS に rbenv を root でインストールする

概要

GCE の起動スクリプトで rbenv をインストールしたときのメモ

#!/bin/bash
set -e

RUBY_VERSION="2.5.1"

apt-get update
apt-get install -y git build-essential libssl-dev libreadline-dev zlib1g-dev libmysqlclient-dev nodejs mysql-client

git clone https://github.com/rbenv/rbenv.git /opt/rbenv
git clone https://github.com/rbenv/ruby-build.git /opt/rbenv/plugins/ruby-build
echo 'export RBENV_ROOT="/opt/rbenv"' >> /etc/profile
echo 'export PATH="${RBENV_ROOT}/bin:${PATH}"' >> /etc/profile
echo 'eval "$(rbenv init -)"' >> /etc/profile
source /etc/profile

rbenv install -s -v $RUBY_VERSION
rbenv global $RUBY_VERSION
gem install -q --no-rdoc --no-ri bundler
rbenv rehash