linux, ubuntu

Howto create VirtualBox Vagrant Development Linux with Ubuntu 14.04

The Today’s Software Developers have to be increasingly more and more aware and skilled in the tools and techniques used to orchestrate and automate the deployment of all the different components that today’s architecture may have.

vagrant-virtualbox-ubuntu-post-title

Lately I’ve been working to manage this topic and get my company moving faster and having more agility when comes to getting a new developer up to speed as fast as possible. Well it turns out that this is not that hard thing to do.

Puppet and Vagrant are really powerful tools in the “devops tools belt”, wait, I won’t be throwing names on you without a little explanation on the topic:

2013-02-18-overview-of-building-vm

Puppet is a provision manager which means it can be used for configuring a machine. You program Puppet by writing manifests which contains declarative specifications to describe the machine configuration. That is instead of instructing Puppet to “you should first install this and then if this condition is met then install this otherwise put a file in this directory. When all this is done, start this service and then …” you write like “Service X must be installed, requires Y and ensure it’s running. File Z must be present and have content C….”

Vagrant is used for managing virtual machines. It makes setting up a machine and tear it down again real easy with just a few commands.

Among all this tools, today I will teach you how to create a reusable working environment that any developer can get and start right away and with just one command, being productive and have all the company tools in it.

So I decided to create one Linux Base Box with Ubuntu 14 and automate all the boring and error prone installation steps converted into just one Vagrant command will bring you and your team all this goods.

Almost all the guides out there focus on Linux distributions without GUI, so I decided that while I am creating my Vagrant Base Box with Ubuntu 14.04 Desktop I would document all the relevant steps:

Step 1: Create the Virtual Machine

– Install VirtualBox
Download from the website: https://www.virtualbox.org/

– Download Ubuntu 14.04 64 bits ISO
Download from the website: http://www.ubuntu.com/download/desktop

– Define your Virtual Machine taking into consideration that:
The first network interface (adapter 1) must be a NAT adapter.
For convenience the Virtual Disk should be Dynamic (VMDK), so don’t bee too stingy with the disk size ( >= 10GB IMO ).
VirtualBox settings

virtualbox

– Load the ISO and install the OS.
– Username and Password should be: vagrant (for convenience, not for security).
– Once installed restart the VM.
– Install the “Guest Additions”
Before installing the Guest Additions, you will have to prepare your guest system for building external kernel modules:


$ sudo apt-get install dkms
$ sudo /etc/init.d/vboxadd setup

Install the build-essential package and linux headers to compile the Guest Additions properly.


$ sudo apt-get install -y build-essential linux-headers-server

Then Mount guest additions ISO via virtualbox window and follow the indications to run the installation script :

VirtualBox Guest Additions

If the sytems does not install it automatically you can use the following commands:

$ sudo mount /dev/cdrom /media/cdrom
$ sudo /media/cdrom/VBoxLinuxAdditions.run
$ sudo umount /media/cdrom
$ sudo apt-get clean

Step 2: Setup guest OS (Ubuntu 14.04 64bit) with the minimum necessary.

– Use “Software Updater” to get latest updates. Or if you are using the command line:

$ sudo apt-get update -y
$ sudo apt-get upgrade -y
# Restart the machine
$ sudo shutdown -r now

– Add the vagrant user to sudoers file:

$ sudo su -
$ visudo

# Add the following line to the end of the file.
vagrant ALL=(ALL) NOPASSWD:ALL

– Install Vagrant Public Keys
This way we can SSH to the machine without entering the password:


$ mkdir -p /home/vagrant/.ssh
$ wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys

# Ensure we have the correct permissions set

$ chmod 0700 /home/vagrant/.ssh
$ chmod 0600 /home/vagrant/.ssh/authorized_keys
$ chown -R vagrant /home/vagrant/.ssh

Install OpenSSH Server

$ sudo apt-get install -y openssh-server
$ sudo vi /etc/ssh/sshd_config

Ensure the following is set:

Port 22
PubKeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
PermitEmptyPasswords no

Save & close the file then restart SSH.
$ sudo service ssh restartter

Install puppet
(for other distros and more info check Using the Puppet Labs Package Repositories )
For more info about ubuntu check Installing Puppet: Debian and Ubuntu


$ apt-get update --fix-missing --force-yes -y
$ apt-get install puppet --fix-missing --force-yes -y

Install GIT with puppet
$ puppet module install puppetlabs-git

Notice: Preparing to install into /etc/puppet/modules ...
Notice: Downloading from https://forge.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppet/modules
└─┬ puppetlabs-git (v0.4.0)
└── puppetlabs-stdlib (v4.9.0)

Install JDK7 with puppet

$ puppet module install puppetlabs-java
Notice: Preparing to install into /etc/puppet/modules ...
Notice: Downloading from https://forge.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppet/modules
└── puppetlabs-java (v1.4.2)

Install InteliJ using Ubuntu Make

First, add the Ubuntu Make ppa:

$ sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
$ sudo apt-get update

Then, install Ubuntu Make:

$ sudo apt-get install ubuntu-make

Then install Idea:
$ umake ide idea
Choose installation path: /home/vagrant/tools/ide/idea
Downloading and installing requirements
100% |########################################################################|
Installing Idea
|##############################################################################|
Installation done

intelij

Install Chrome (3rd Party Repository: Google Chrome)

chrome

a) Add google repository to your sources

$ sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'

b) Get the repo key:

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -

c) Update

sudo apt-get update -y

d) Install

sudo apt-get install google-chrome-stable -y

Install MongoDB
a) Import the public key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

b) Create a list file for MongoDB
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

c) Update

sudo apt-get update -y

d) Install the MongoDB packages.

sudo apt-get install -y mongodb-org

5) Install Terminator

sudo add-apt-repository ppa:gnome-terminator
sudo apt-get update -y
sudo apt-get install terminator

terminator

6) Install Skype

sudo echo "deb http://archive.canonical.com/ubuntu trusty partner" | sudo tee -a /etc/apt/sources.list.d/canonical_partner.list
sudo apt-get update -y
sudo apt-get install skype

skype

7) Install Maven

$ sudo apt-get install maven -y

mvn

8) Install SVN:
sudo apt-get install -y subversion

Step 3: Package the Box

packthebox

Compact space

$ sudo dd if=/dev/zero of=/EMPTY bs=1M
$ sudo rm -f /EMPTY

Shutdown the VM
$ sudo shutdown -h now

Create Vagrant Base Box

Asuming you already have Vagrant installed in the host system, just run the following command:

$ vagrant package --base ubuntu-desktop-14-04-x64
==> ubuntu-desktop-14-04-x64: Exporting VM...
==> ubuntu-desktop-14-04-x64: Compressing package to: (...)/ubuntu12/package.box

This will create a file called package.box under the directory you are currently in. (just make sure the name ubuntu-desktop-14-04-x64 is the same name as you see when opening the virtualbox window).

Install the box


$ vagrant box add ubuntu-desktop-14-04-x64 package.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'ubuntu-desktop-14-04-x64' (v0) for provider:
box: Unpacking necessary files from: file://(...)/ubuntu12/package.box
box: Progress: 100% (Rate: 279M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'ubuntu-desktop-14-04-x64' (v0) for 'virtualbox'!

So now, you can Init a Vagrant Box by referencing the Base one we have created.
This is what all your team members should do, once they execute vagrant `box add ubuntu-desktop-14-04-x64 package.box`

Go to a different folder and type:
$ vagrant init ubuntu-desktop-14-04-x64

This will then create a Vagrantfile inside your current directory, you should now Open this file and enable the GUI (Graphic User Interface)
Edit the generated Vagrantfile by uncommenting the following lines: (in my case, 46,48,52)


config.vm.provider "virtualbox" do |v|
v.gui = true
end

If you want to have a common shared folder between your Host and the Guest (where host is for example Windows and Guest is your new Ubuntu) do the following changes to your Vagrantfile:
Uncomment line 40:
config.vm.synced_folder “data”, “/vagrant_data”

This will make the folder data that is under the same directory where your Vagrantfile is to be in sync with the Ubuntu 🙂

Common errors:
After running vagrant up, I got into this error, what should I do?


Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:
vm:
* The host path of the shared folder is missing: data

You should create the folder vagrant is complaining about by running:
$ mkdir data

$ vagrant up
vagrantup

We are all done, you can now start using your new VirtualBox Vagrant Ubuntu 14.04 With all your favorite tools in it 🙂

virtualbox3

Advertisements

1 thought on “Howto create VirtualBox Vagrant Development Linux with Ubuntu 14.04”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s