Created
February 27, 2017 18:52
-
-
Save creisor/e20f254a89070f46b91cc3e0c5cd18db to your computer and use it in GitHub Desktop.
Vagrant file for installing ruby with rbenv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very clean and good ideas. Thanks for sharing!