Skip to content

Instantly share code, notes, and snippets.

@danigb
Last active July 27, 2022 08:32
Show Gist options
  • Save danigb/5dd50742fa73ad456290abe8cd532b6c to your computer and use it in GitHub Desktop.
Save danigb/5dd50742fa73ad456290abe8cd532b6c to your computer and use it in GitHub Desktop.
Vagrant setup for ruby 1.8

How to create and setup a development virtual machine for old ruby/rails

Using VirtualBox and Vagrant

Install and create a virtual machine

Install virtualbox and Vagrant:

$ brew cask install virtualbox
$ brew cask install vagrant

Add ubuntu 12.4

$ vagrant box add precise64 http://files.vagrantup.com/precise64.box

Setup the vagrant box for your project:

$ cd myproject
$ vagrant init precise64

Configure the virtual machine

All the configuration is done by editing the Vagrant file.

First add a shared folder to see the current folder from the virtual machine:

config.vm.synced_folder ".", "/home/vagrant/my-project"

Then add forwarded ports to connect to the web server of the VM from outside:

config.vm.network "forwarded_port", guest: 3000, host: 3333

Start the VM and login

Start and connect to the virtual machine:

$ vagrant up
$ vagrant ssh

If you want make changes to Vagrant file you need to reload:

$ vagrant reload

Ubuntu setup

All the following steps are required to be executed inside the vm unless notice

Install the required software:

$ sudo apt-get update
$ sudo apt-get install 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

Install rbenv:

$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ cd ~/.rbenv && src/configure && make -C src
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Install ruby-build:

$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc

Reload bashrc:

$ source ~/.bashrc

Install ruby:

$ rbenv install 1.8.7-p374

Install mysql:

$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev
$ gem install mysql2

App setup

Install bunlder:

$ gem install bundler
$ rbenv rehash

and install dependencies:

$ bundle

With an old ruby (~1.8) I needed to add an older version of rdoc to the Gemfile:

gem 'rdoc', '4.2.0'

And then the classic stuff:

rake db:create db:migrate
script/server

Hopefully you can connect to http://localhost:3333 and see the app running. Congrats!

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