Skip to content

Instantly share code, notes, and snippets.

@nruth
Created February 11, 2015 02:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nruth/d99f3395e46678585614 to your computer and use it in GitHub Desktop.
Save nruth/d99f3395e46678585614 to your computer and use it in GitHub Desktop.
vagrant ubuntu 14.04 rbenv mysql for rails
Vagrant.configure(2) do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = 'ubuntu/trusty64'
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 3000, host: 3000
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
config.vm.synced_folder './vagrant-config', '/vagrant-config'
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
# vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "2048"
# fix broken DNS in virtualbox for some users
vb.customize ['modifyvm', :id, "--natdnshostresolver1", "on"]
end
config.vm.provision 'shell', privileged: true, inline: <<-SHELL
# if you have some mysql preferences
cp /vagrant-config/my.cnf /home/vagrant/.my.cnf
# reduce terminal chatter by setting your locale
locale-gen en_GB.UTF-8
# for event machine (And others)
apt-get install -y build-essential
# for nokogiri
apt-get install -y zlib1g-dev
apt-get install -y git-core
apt-get install -y nodejs
# breaks mac console so mute stdout of this install
# http://stackoverflow.com/questions/7739645/install-mysql-on-ubuntu-without-password-prompt
DEBIAN_FRONTEND=noninteractive apt-get install -q -y mysql-server-5.5 1> /dev/null
apt-get install -y libmysqlclient-dev
# https://github.com/sstephenson/ruby-build/wiki#suggested-build-environment
apt-get install -y autoconf bison build-essential libssl-dev libyaml-dev
apt-get install -y libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev
apt-get install -y libgdbm3 libgdbm-dev
apt-get install -y libreadline-dev libssl-dev libffi-dev
SHELL
config.vm.provision 'shell', privileged: false, inline: <<-SHELL
# download rbenv if the directory is missing
RBENV_VERSION=7e0e85bdda092d94aef0374af7
if cd ~/.rbenv && git rev-parse --verify --short=26 HEAD | grep -q $RBENV_VERSION; then
echo 'rbenv already downloaded at expected revision'
else
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
cd ~/.rbenv && git checkout $RBENV_VERSION
fi
# download ruby-build if the directory is missing
RBBUILD_VERSION=8106d8f33ff2ec888a2ced5348
if cd ~/.rbenv/plugins/ruby-build && git rev-parse --verify --short=26 HEAD | grep -q $RBBUILD_VERSION; then
echo 'ruby-build already downloaded at expected revision'
else
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
cd ~/.rbenv/plugins/ruby-build && git checkout $RBBUILD_VERSION
fi
RBENV_PATH='export PATH="$HOME/.rbenv/bin:$PATH"'
if grep -q "$RBENV_PATH" ~/.bash_profile ; then
echo 'rbenv path already in .bash_profile'
else
echo $RBENV_PATH >> ~/.bash_profile
fi
RBENV_INIT='eval "$(rbenv init -)"'
if grep -q "$RBENV_INIT" ~/.bash_profile ; then
echo 'rbenv init already in .bash_profile'
else
echo $RBENV_INIT >> ~/.bash_profile
fi
SHELL
config.vm.provision 'shell', privileged: false, inline: <<-SHELL
rbenv install 2.1.5
rbenv global 2.1.5
SHELL
config.vm.provision 'shell', privileged: false, inline: <<-SHELL
gem install bundler
cd /vagrant
bundle install
bundle exec rake db:create
bundle exec rake db:schema:load
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment