Module: Prepper::Tools::Rbenv

Included in:
Package
Defined in:
lib/prepper/tools/rbenv.rb

Overview

Helper methods for rbenv

Instance Method Summary collapse

Instance Method Details

#install_rbenv(user) ⇒ Object

install rbenv for a given user

Parameters:

  • user (String)

    name of the user to install rbenv for



7
8
9
10
11
12
13
14
15
# File 'lib/prepper/tools/rbenv.rb', line 7

def install_rbenv(user)
  apt_install %w{libssl-dev zlib1g zlib1g-dev libreadline-dev}
  @commands << Command.new("sudo -u #{user} -i git clone https://github.com/sstephenson/rbenv.git /home/#{user}/.rbenv", verifier: has_directory?("/home/#{user}/.rbenv"))
  @commands << Command.new("sudo -u #{user} -i git clone https://github.com/sstephenson/ruby-build.git /home/#{user}/.rbenv/plugins/ruby-build", verifier: has_directory?("/home/#{user}/.rbenv/plugins/ruby-build"))

  append_text 'export PATH="$HOME/.rbenv/bin:$PATH"', "/home/#{user}/.profile"
  append_text 'eval "$(rbenv init -)"', "/home/#{user}/.profile"
  chown "/home/#{user}/.profile", "#{user}:#{user}"
end

#install_ruby(user, version, opts = '') ⇒ Object

install a given ruby version for a given user

Parameters:

  • user (String)

    name of the user

  • version (String)

    ruby version



20
21
22
23
24
25
26
# File 'lib/prepper/tools/rbenv.rb', line 20

def install_ruby(user, version, opts = '')
  @commands << Command.new("sudo -u #{user} -i RUBY_CONFIGURE_OPTS='#{opts}' rbenv install #{version}", verifier: has_directory?("/home/#{user}/.rbenv/versions/#{version}"))

  @commands << Command.new("sudo -u #{user} -i rbenv rehash")
  @commands << Command.new("sudo -u #{user} -i rbenv global #{version}")
  @commands << Command.new("sudo -u #{user} -i rbenv rehash")
end