Ubuntu – How to install openjdk-7-jdk on Ubuntu 12.04 without dragging in unrelated GUI and sound packages

javajdkopenjdksoftware installation

Ubuntu 12.04.2 LTS

What's going on here?

# apt-get install openjdk-7-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  consolekit cryptsetup-bin dbus-x11 dconf-gsettings-backend dconf-service
  gconf-service gconf-service-backend gconf2 gconf2-common gvfs gvfs-common
  gvfs-daemons gvfs-libs libatasmart4 libavahi-glib1 libbonobo2-0
  libbonobo2-common libcairo-gobject2 libcanberra0 libck-connector0
  libcryptsetup4 libdconf0 libfontenc1 libgconf-2-4 libgconf2-4 libgdu0
  libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libgnome-keyring-common
  libgnome-keyring0 libgnome2-0 libgnome2-bin libgnome2-common libgnomevfs2-0
  libgnomevfs2-common libgtk-3-0 libgtk-3-bin libgtk-3-common libgudev-1.0-0
  libidl-common libidl0 libllvm3.0 libltdl7 liblvm2app2.2 liborbit2
  libpam-ck-connector libpolkit-agent-1-0 libpolkit-backend-1-0 libsgutils2-2
  libtdb1 libvorbisfile3 libx11-xcb1 libxaw7 libxcb-glx0 libxcb-shape0 libxmu6
  libxpm4 libxv1 libxxf86dga1 libxxf86vm1 mtools openjdk-7-jre policykit-1
  policykit-1-gnome sound-theme-freedesktop udisks x11-utils

Is it possible to install the JDK without half of Gnome and X11? And sound themes? This is a headless (and speakerless) server.

Best Answer


I personally try to avoid Java because in my opinion it is very clumsy. These instructions are pieced together from various sources, I had to install Java recently and this should work for you.

If your licensing requirements permit, install Oracle Java. Download java from here, you need to chose which one you need based on what you have installed.

JDK x64

wget --no-check-certificate --no-cookies - --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz

JDK x32

wget --no-check-certificate --no-cookies - --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-i586.tar.gz

JRE x64

wget --no-check-certificate --no-cookies - --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jre-7u51-linux-x64.tar.gz

JRE x32

wget --no-check-certificate --no-cookies - --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jre-7u51-linux-i586.tar.gz

Note that you need a workaround for wget and oracle to play nice together.

Create a directory where your Java will live:

sudo mkdir -p /usr/lib/jvm

Move the downloaded Java:

sudo mv jdk-7u51-linux-x64.tar.gz /usr/lib/jvm

Extract Java:

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

Tell Ubuntu that Java exists:

sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_51/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_51/bin/java 1
sudo update-alternatives --set javac /usr/lib/jvm/jdk1.7.0_51/bin/javac
sudo update-alternatives --set java /usr/lib/jvm/jdk1.7.0_51/bin/java

Add java path to your system profile, so that the machine knows where the Java binaries are:

sudo nano /etc/profile

At the end of the file add this:

export JAVA_HOME
export PATH

Save and reboot.

Test your Java installation:

java -version