Skip to content

Instantly share code, notes, and snippets.

@harry-wood
Last active January 3, 2017 15:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harry-wood/9d7ccdda4553604ff5face493ef0e019 to your computer and use it in GitHub Desktop.
Save harry-wood/9d7ccdda4553604ff5face493ef0e019 to your computer and use it in GitHub Desktop.
Vagrantfile for jekyll (ruby2 rbenv bundle-installed project)
Vagrant::Config.run do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.forward_port 4000, 4000
$script = <<-SCRIPT
set -o verbose
set -e
whoami
sudo apt-get -y update
sudo apt-get -y remove ruby1.9.1 #comes installed on this vagrant box. remove
sudo apt-get -y install build-essential git curl zlib1g-dev libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# The following need to be done in simulated interactive mode otherwise the
# the rbenv specified ruby doesn't entirely work and vagrant install fails
sudo -H -u vagrant bash -i -c 'rbenv install 2.3.1'
sudo -H -u vagrant bash -i -c 'rbenv rehash'
sudo -H -u vagrant bash -i -c 'rbenv global 2.3.1'
sudo -H -u vagrant bash -i -c 'gem install bundler --no-ri --no-rdoc'
sudo -H -u vagrant bash -i -c 'rbenv rehash'
sudo -H -u vagrant bash -i -c 'cd /vagrant && bundle install'
sudo -H -u vagrant bash -i -c 'bundle exec jekyll --version'
# Well this last step doesn't work "Inappropriate ioctl for device".
# anyone know how to fix that?
# Run it directly by doing doing 'vagrant ssh' then
# 'cd /vagrant && bundle exec jekyll serve --host 0.0.0.0'
sudo -H -u vagrant bash -i -c 'bundle exec jekyll serve --host 0.0.0.0'
# end of bash script
SCRIPT
config.vm.provision "shell", inline: $script, privileged: false
config.ssh.forward_agent = true
end
@harry-wood
Copy link
Author

This was a vagrant script I fiddled with for way too long. Also discussed here: https://talk.jekyllrb.com/t/install-problem-with-rbenv/3068/3 It's kind of working, but for the automation of starting the server at the end there.

But the ultimate thing which took me way too long to realise, is that while there's lots of rbenv advice out there, life is far easier if ubuntu packages are available with the ruby version you want, which (and I failed to understand this initially) you get if you're on a later version of ubuntu. Easy with vagrant. Just start from a different base box. With a 'xenial32' base box you can just install a 'ruby2.3' ubuntu package! Job done. Alternatively use "ppa packages". I'm told http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu is the normal solution on older ubuntus

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