Provisioning Ubuntu With Java in 3 Steps

As I’ve written about before, Vagrant is handy tool for creating localized VMs. It’s a lot like firing up EC2 images, but, for the most part, things are localized (you can, by the way, use Vagrant to fire up EC2 images). If you’ve ever used VMWare before, its the same thing, except Vagrant is free. You can create VMs of various operating systems, fire them up, and tear them down all with ease.ubuntu

Vagrant plays nicely with hip DevOps frameworks like Chef and Puppet and if your installations require a number of components, then these tools are defiantly the way to go. Sometimes, however, a simple Bash script is good enough as in the case for auto-installing some base component, like Java, Node.js or Ruby.

Using Vagrant’s configuration file, aptly dubbed Vagrantfile, you can instruct a VM instance to run a series of steps – these steps can be simple shell scripts, Chef cookbooks, or the Puppet equivalent.

Accordingly, the first step to provision an Ubuntu box with Java is to initialize a 64-bit Ubuntu 12.04 LTS (Precise Pangolin) instance. You can do this via the vagrant init command like so:

Initializing a Vagrant box

$> vagrant init ubuntu.lts.64 http://files.vagrantup.com/precise64.box

This creates a Vagrantfile in the directory where you ran the command and creates a named VM (i.e. “ubuntu.lts.64”) that is based off of Ubuntu 12.04 LTS.

Base Ubuntu installations do not come with Java; if you’d like to install a particular JDK, say Oracle’s JDK 7, you can leverage ubuntu-equip, which is a series of Bash scripts that install various components like Java, Node.js, MongoDB, Redis, Ruby, etc.

Thus, for step 2, open up the newly created Vagrantfile and you should see two lines like so:

A basic VagrantFile contains the box and box_url attributes

config.vm.box = 'ubuntu.lts.64'
# a few comments...
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'

After the vm.box_url declaration, insert the following line:

Installing Java

config.vm.provision :shell, inline: 'wget --no-check-certificate https://github.com/aglover/ubuntu-equip/raw/master/equip_java7_64.sh && bash equip_java7_64.sh'

This command instructs the instance to run an inline Bash command once it is up and running, which in this case auto-installs Oracle’s Java 7 JDK (see the ubuntu-equip project for more information).

Save your VagrantFile and then, for step 3, run the following command in the same directory:

Firing up a new VM

$> vagrant up

If this is the first time firing up this particular VM, you should see some text indicating that a particular box is being downloaded. Once the download is complete, the instance will boot up and subsequently invoke the inline provision command that kicks off the installation of Java.

If all goes well, you should see a lot of text scroll by ending with:

Java is installed!

java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

And that’s it. To use the VM, simply SSH to it. Go ahead and type java -version just to convince yourself. Go ahead, I’ll wait for you…there, are you happy now? Wasn’t that easy? Provisioning Ubuntu VMs with Vagrant couldn’t be any easier with ubuntu-equip, dig it?
 

Reference: Provisioning Ubuntu With Java in 3 Steps from our JCG partner Andrew Glover at the The Disco Blog blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

One Response to "Provisioning Ubuntu With Java in 3 Steps"

  1. Bill Fly says:

    Too bad you can’t read the article for the advertising bar down the right side. The config.vm.provision command to install Java extends all the way to the right side of the page emerging from the right side of the advertising bar. That line was the primary piece of information, but it was lost to the advertising.

Leave a Reply


5 − = zero



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close