Skip to content

Setting up a Virtual Development Environment using Vagrant

Linda Nichols edited this page Oct 11, 2013 · 2 revisions

Creating a Vagrant Virtual Development Environment

Vagrant is open-source software used to create lightweight and portable virtual development environments. Vagrant works like a "wrapper" for VirtualBox that can create, configure, and destroy virtual machines with the use of its own terminal commands. This facilitates the setup of environments that do not require any direct interaction with VirtualBox and allows developers to use software development tools in their native operating system.

Install Vagrant

  • Make sure that you first have VirtualBox installed
  • Download and install Vagrant here ** Package managers like apt-get and gem install are installing an older version, so the download is recommended.

Setup Vagrant

Create a Vagrant home folder where all Vagrant commands will be executed:

mkdir vagrant/xtuple
cd vagrant/xtuple

Create Vagrant Configuration File

In the Vagrant home folder, use the Vagrant initialize command:

vagrant init

Now, edit the Vagrantfile that was just created by the initialize command and change these parameters:

config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder "dev", "/home/vagrant/dev"

config.vm.provider "virtualbox" do |v|
  v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
  v.customize ["modifyvm", :id, "--memory", "1024"]
end

config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 443, host: 8443

This Vagrantfile holds configuration settings that Vagrant uses to create a new Virtual Machine. This Vagrantfile can now be used by other team members (instead of vagrant init) to create an identical virtual development environment.

Create a new Virtual Machine Box

The xTuple mobile-web development requires an Ubuntu 64 bit virtual machine. Vagrant can download this virtual machine from the url specified during this box creation:

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

Create a Synced Folder

Add a new folder that will serve as a synced folder for development on the host machine. This folder is already referenced in the Vagrantfile configuration:

mkdir dev

Connect to the Virtual Machine

Start the virtual machine:

vagrant up

Connect to the virtual machine via ssh:

vagrant ssh

Setup the xTuple Development Environment

The xTuple mobile web client files are maintained on github.com. You will need an account there to execute the following steps:

  • Log in to github.com
  • Navigate to the xTuple project: https://github.com/xtuple/
  • Fork the client repository:
    • Click on client
    • Click on Fork in the upper right-hand corner of the browser window
    • Click the Fork to your-username button

Install git on the virtual machine (requires vagrant ssh into the virtual machine):

sudo apt-get install git

Create an SSH keypair so GitHub can authenticate your push requests:

ssh-keygen # this isn't extremely secure but it'll do
cat ~/.ssh/id_rsa.pub
ssh-rsa AAA[...about 200 more characters]...M8n8/B xtuple@mobiledevvm

The cat command shows the public key that was just generated. Copy this text, starting with the ssh-rsa at the beginning and ending with the xtuple@mobiledevvm at the end (select and either right-click > Copy or Control-Shift-C in the Linux Terminal window).

In your web browser, navigate to your home page on GitHub. Click on Edit Your Profile. Select SSH Keys from the list on the left. Click Add SSH Key. Give this SSH key a title, such as "xTuple Mobile Dev VM", then paste the public key into the Key field. Finally click the Add key button. GitHub will verify your password just to make sure it's you at the keyboard.

Go to the Vagrant synced folder on the virtual machine:

cd dev

Clone the xTuple code from your fork into a local directory:

git clone [email protected]:{yourusername}/xtuple.git

You can now run the install script as described on the main project README.

Additional Information

  • This virtual machine created by Vagrant can also be opened in VirtualBox for direct access to Ubuntu.
  • This virtual machine has a static IP Address of 192.168.33.10 that can be added with an alias to the hosts file on the host operating system.
  • Edit pg_hba.conf in the VM to add your machine IP so that you can access the postgres install with PgAdmin outside of the VM: cd/etc/postgresql/[postgres version]/main.
  • The synced folder dev allows for files to be edited in either the virtual machine or on the host machine and the files will be synced both ways.