Windows/Unix development on Mac Part 3: A Vagrantfile for Unix/Intellij

September 22, 2016 06:01

The first VM I wanted was Centos6.5 on which IntelliJ would run. (Just for fun I created an Ubuntu16 VM and installed IntelliJ, and the performance was wretched. On Centos6.5 it was super snappy, however. Default GUIs on both.)

Here’s what I came up with (with their helpful comments stripped):

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # Available boxes seem to either have no GUI (can’t run IntelliJ), 
  # or included LibreOffice (too much bloat!)
  # This box comes with a working GUI and just the essentials (like Terminal). 
  # IntelliJ installed on this box without a hitch. = "NinjaHamster/CentOS6.5-gui-dev-base"

  # the hostname 

  # I want to be able to run my own toolbox
  config.vm.synced_folder "~/bin", "/zbin"

  config.vm.provider "virtualbox" do |vb|
     # Display the VirtualBox GUI when booting the machine (that’s the whole idea!)
     vb.gui = true
     # Customize the amount of memory on the VM:
     vb.memory = "8192"

  config.vm.provision "file", source: "./bashrc2", destination: "/home/vagrant/.bashrc2"
  config.vm.provision "shell", inline: <<-SHELL

  # update .bashrc
  echo >>$VHOME/.bashrc "if [ -f $VHOME/.bashrc2 ]; then\n\t. $VHOME/.bashrc2\nfi"
  chmod 755 $VHOME/.bashrc2

  yum update -y

  # Java:
  yum install -y java-1.7.0-openjdk-devel
  echo >>/etc/environment JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-

  # Git:
  yum install -y git-all


One of the things the script accomplishes is that I like touching the stock .bashrc as little as possible, so it checks for the existence of .bashrc2, and if present executes that as well. bashrc2 contains:

PS1='\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\H: \[\033[01;37m\]\w\n\$\[\033[00m\] '
tabs 4
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/bin:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

Ha ha PS1 changes the prompt to one that includes hostname to help me keep track of which machine I'm on! (And it's more colorful.)


Updating Guest Plugins

Vagrant uses ‘Guest Additions’ which “consist of device drivers and system applications that optimize the guest operating system for better performance and usability.” If these become out of sync with your box, bad things can happen, including:

  • Warning message
  • Shares won't mount

The solution is to run this in your Vagrantfile folder.

vagrant plugin install vagrant-vbguest

"Warning: Authentication failure. Retrying... "

SSH logon seems somewhat fragile, as can be seen from this thread. The usual ssh trouble shooting applies (e.g. regenerate keys, etc).

But it all else fails, you can disable ssh authentication by adding the following to your Vagrantfile:


This does mean that when you run vagrant ssh, you will have to enter the password vagrant.

Set the following so the gui comes up, so you can log on as vagrant pwd: vagrant and check permissions on the VM side:

config.vm.provider "virtualbox" do |vb|
  vb.gui = true

Hostname is not Correct

This has been due to two entries in /etc/hosts for ''. The first line will have the hostname you want, the second won't, and apparently the last one wins. Delete the second erroneous line, exit, and vagrant reload to reboot the machine.

    Previous    Next