Linux – Installing a minimal java on Ubuntu VM

javalinuxUbuntu

I don't have java installed on a Ubuntu virtual machine (just server, no X11):

bash: java: command not found

I want to install a minimal version to run some scripts. When I issue:

sudo apt-get install openjdk-7-jre

It tries to install 109 packages, and some of them are x11-common x11-utils sound-theme-freedesktop

I want to avoid having to install such a beast with such a lot of unneeded stuff. Is there a way to install a more minimal java that will suit me to run console apps.

Best Answer

Try getting the jvm in .tar.gz format from oracle:

http://www.oracle.com/technetwork/java/javase/downloads/index.html?ssSourceSiteId=otnjp

Get the server JRE or JDK for instance:

jdk-7u51-linux-x64.tar.gz

Untar it into /opt:

java -> jdk1.7.0_51/

Make a symlink to /opt/java

ln -s /opt/jdk1.7.0_51 /opt/java

Set JAVA_HOME=/opt/java

Put /opt/java/bin somewhere on your path.

You should then be able to run which java and see it come from /opt/java` and finallyjava -version`` should report the version of java you just downloaded.

This keeps everything outside of the operating system's package management system and dependencies, which is why ubuntu is trying to load all those extra packages. It also means that you don't have to worry about breaking your java when you update your Ubuntu. You just need to make sure you keep java reasonable upto date yourself.