Installing
Vagrant can be installed on Ubuntu via apt-get, but the version is really old. I downloaded the .deb -file from http://www.vagrantup.com/downloads.html.
Configuring
First create a folder for your project and go to that folder. The following command will initialize a new vagrant virtual machine and use Ubuntu Precise as the base:
$ vagrant init precise32 http://files.vagrantup.com/precise32.box
Vagrant will also create a Vagrantfile in the working directory. Open the file for editing and the change the following line:
1 2 3 4 |
|
to
1 2 3 4 |
|
to forward the default Rails development port to the virtual machine. Now create two script files to the same directory with Vagrantfile. We will include all software installation in those scripts. You can name the scripts as you like, the names that I use are just examples:
$ nano installation.sh
I have put the following commands into the first scripts that will be run as root. Feel free to customize these commands to your liking. Node.js is included because its needed for some javascript operations:
1 2 3 4 |
|
After this create another script file to be run as normal user. The script will first install rbenv for easy switching between different Ruby versions. Then it will install a version of Ruby, in my case 2.1.0. It will then set that version of Ruby to be the global default. Finally it will install Rails and Bundler:
$ nano installation_user.sh
1 2 3 4 5 6 7 8 9 10 |
|
After this add the following lines to Vagrantfile to include your new shell scripts:
1 2 |
|
After this the configuration for your Ruby on Rails development environment should be configured and you can start the Vagrant box with the following command:
$ vagrant up
The startup will take some time the first time because it will install the whole system like you previously configured. After the process has finished you can ssh to your new virtual machine with the command:
$ vagrant ssh
The directory where you most likely will want to initialize your Rails project(s) inside the virtual machine is:
/vagrant/
Since it will be shared between your guest and host machine. You should now be set up to start developing your application.