Skip to content

Instantly share code, notes, and snippets.

@creisor
Created February 27, 2017 18:52
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save creisor/e20f254a89070f46b91cc3e0c5cd18db to your computer and use it in GitHub Desktop.
Save creisor/e20f254a89070f46b91cc3e0c5cd18db to your computer and use it in GitHub Desktop.
Vagrant file for installing ruby with rbenv
# -*- mode: ruby -*-
# vi: set ft=ruby :
RUBY_V = File.open("./.ruby-version") { |f| f.read }.chomp
$apt_script = <<SCRIPT
sudo apt-get update
sudo apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev libmysqlclient-dev
SCRIPT
$rbenv_script = <<SCRIPT
if [ ! -d ~/.rbenv ]; then
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
fi
if [ ! -d ~/.rbenv/plugins/ruby-build ]; then
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
fi
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
eval "$(rbenv init -)"
if [ ! -e .rbenv/versions/#{RUBY_V} ]; then
rbenv install #{RUBY_V}
fi
cd /vagrant
if [ ! -e /home/vagrant/.rbenv/shims/bundle ]; then
gem install bundler
rbenv rehash
fi
bundle install
SCRIPT
Vagrant.configure("2") do |config|
config.vm.define :ruby do |deploy_config|
deploy_config.vm.box = "hashicorp/precise64"
deploy_config.vm.hostname = "deploy"
deploy_config.vm.provider "virtualbox" do |vb|
vb.memory = "256"
end
deploy_config.ssh.forward_agent = true
deploy_config.vm.provision :shell, inline: $apt_script
deploy_config.vm.provision :shell, privileged: false, inline: $rbenv_script
end
end
@deepflame
Copy link

very clean and good ideas. Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment