Getting started with Vagrant for Java Developers: Vagrant, Virtual Box, Cent OS (Linux) and Java JDK 8

Here’s a tutorial to get started with Vagrant, the easiest way to work with virtual machines on any OS.


Why Vagrant?

  • Quick and easy way to get a virtual machine (VM) up and running with SSH.
  • Gives the capability to share environment as a file.
    For example – If your application development involves a lot of tools/softwares like MySQL, MongoDB, Kafka, RabbitMQ, ELK etc., it’s easy to share environment setup as a simple vagrantfile which can help anyone have environment up and running in no time.
  • No need to download and install VM images yourself.

In this example, we will setup a virtual machine running CentOS (Linux) with Java JDK 8 installed.


  1. Virtual Box
  2. Vagrant


# Configurations
ram = 2048			#ram in mb
storage = 20		#hdd size in gb for vm

Vagrant.configure("2") do |config| = "bento/centos-6.7"
	config.vm.hostname = "centos-vm-1" :forwarded_port, guest: 22, host: 12822, id: 'ssh' :private_network, ip: ""

	config.vm.provider "virtualbox" do |v| = "centos-vm-1"
	  v.customize ["modifyvm", :id, "--memory", "#{ram}"]
	  v.customize ["modifyvm", :id, "--usb", "off"]
	  v.customize ["modifyvm", :id, "--usbehci", "off"]


yum update -y

cd /tmp
wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""

sudo yum local install -y jdk-8u60-linux-x64.rpm

rm jdk-8u60-linux-x64.rpm

Steps / Execution

  1. Create a directory with name ‘centos-vm’.
  2. Change to directory ‘centos-vm’.
  3. Create a file with name ‘Vagrantfile’ with contents given above.
  4. Create a file with name ‘’ with contents given above.
  5. Execute command ‘vagrant up’ – to download the image from internet and provision the virtual machine as per ‘’ for the first time. Sub-sequent times, this command will just start the virtual machine.
  6. Execute command ‘vagrant ssh’ – to login to the virtual machine with ssh.
  7. Execute command ‘java -version’ – to test if the virtual machine has java installed properly.


  • Vagrantfile has all the configurations required for the virtual machine, like –
    • ram (2048MB)
    • storage (20GB)
    • the image we want to install (“bento/centos-6.7”), there are images available for almost all the linux based operating systems.
    • static ip for the vm (
    • ssh port forwarding (12822) – just in case if you want to run more than one vm and/or you don’t want to use the default ssh port 22 on the host machine. You may also want to do port-forwarding if you choose to install other services like tomcat, mysql etc.,
  • You can extend this tutorial to include installations for other tools like mysql, tomcat etc.,

Please feel free to comment for questions, issues and suggestions.

Please share if this tutorial is helpful.

This entry was posted in java and tagged , , , , , , . Bookmark the permalink.

One Response to Getting started with Vagrant for Java Developers: Vagrant, Virtual Box, Cent OS (Linux) and Java JDK 8

  1. Anonymous says:

    thanks for your information.
    only one thing cause syntax error, in section, the ip of private network should end with ” .


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s