I Installed vagrant on my machine with hashicorp-precise32 virtual machine. It installed java 1.6 whereas i want java 1.8. Do i have to install another virtual machine? How to get java 1.8?
Asked
Active
Viewed 7,001 times
3
-
that image might have outdated version of Java, write a chef or other provisioner tool to get it upgraded to java 8 or create an image with Java8 and reuse it – jmj Jun 02 '15 at 18:57
-
The answers given build upon the [Ubuntu Personal Package Archive](http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html) (PPA) to obtain java 8. There is also a [gist with the Vagrant provision block](https://gist.github.com/tinkerware/cf0c47bb69bf42c2d740) based on that same PPA. – avandeursen Oct 19 '15 at 11:58
-
Consider upgrading to a 14.04 or 16.04 image. – Thorbjørn Ravn Andersen Oct 26 '16 at 12:56
2 Answers
8
Add below lines in your Vagrantfile, It will install Java 8 (accepting licenses)
and also set the Environmental variables in your guest VM:
sudo apt-get install -y software-properties-common python-software-properties
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update
sudo apt-get install oracle-java8-installer
echo "Setting environment variables for Java 8.."
sudo apt-get install -y oracle-java8-set-default
Moreover, you can refer Creating and Provisioning VM using Vagrant

Arpit Aggarwal
- 27,626
- 16
- 90
- 108
-
Thanks Arpit, it worked. But i am still getting java.lang.UnsupportedClassVersionError, Unsupported major.minor version 52.0. Is tomcat still picking up older version? Any idea? – P.K Jun 02 '15 at 19:43
-
Check your Tomcat , JAVA_HOME version or refer my article, you will get your answer. – Arpit Aggarwal Jun 02 '15 at 19:45
-
JAVA_HOME is empty and default is 1.8 now. Also tomcat is picking up the default but still getting that exception. Btw where can i find your article? Sorry i am a newbie here. – P.K Jun 02 '15 at 19:59
-
You can login to Tomcat manager from host and check which version of JAVA, tomcat is picking and more you can refer: http://www.dzone.com/articles/vagrant – Arpit Aggarwal Jun 02 '15 at 20:02
-
Your article was very helpful. Thanks a lot. I got it working. I build the war on VM using gradle and it worked. – P.K Jun 03 '15 at 00:25
1
It depends on the os you put on the virtualbox, the one you installed has ubuntu so you will want to follow instructions from here
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
$ sudo apt-get install oracle-java8-set-default

Epicblood
- 1,167
- 2
- 10
- 29
-
It will install Java 8 but ask user to accept the permission and when you are working with Vagrant, you don't have control over it. – Arpit Aggarwal Jun 02 '15 at 19:23
-
@Arpit start up a vagrant machine, ssh in, and run these commands. It installs it just fine. – Epicblood Jun 02 '15 at 19:24
-
If I want to create the VM from same vagrant file again, then again I need to install Java 8(If I need), correct? – Arpit Aggarwal Jun 02 '15 at 19:27
-
@arpit yes if you want to move the vm to a different machine then yes, you will have to edit the vagrant file. – Epicblood Jun 02 '15 at 19:32
-