16

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.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
Dr.Haribo
  • 263
  • 2
    Does it help if you add the --no-install-recommends option? – gertvdijk May 30 '13 at 14:53
  • 3
    Why do you need Java Development Kit in a headless server? If you only want to run java applications usually all you need is the Runtime Environment. Try and see if openjdk-7-jre-headless suits your needs. – Eric Carvalho May 30 '13 at 15:26
  • 10
    @EricCarvalho Here's one use case: a continuous integration server building the Java sources. Building Java software on a headless server isn't that exotic. – gertvdijk May 30 '13 at 15:30
  • 3
    @gertvdijk Got it. Then I think this is a bug. There should be a openjdk-7-jdk-headless package. – Eric Carvalho May 30 '13 at 15:34
  • 2
  • @EricCarvalho JDK contains Java compiler. Tomcat webserver compiles JSP pages with Java compiler. On cloud server size is important when you do Snapshot of virtual machine. So headless JDK make sense. – Max Nov 24 '13 at 14:20
  • @EricCarvalho it's hard to decide if this is a bug or not. I had to work on a headless AS400, and was put in a very painful position because the administrator there decided the same thing. Of course that does sound different than what the OP is doing here, sounds like OP wants light transient environment not something expected to run for 10 years... but some of the graphics libraries were needed for rendering, fonts included. Sound libraries would be needed to produce sound applications (pbx integration possibly?). Assumptions can be a pain. – Quaternion Jan 27 '14 at 15:48
  • --no-install-recommends cut the number of packages from 154 newly-installed to 50 newly-installed. A lot of it is x-windows but you can always use that stuff to support xvfb/selenium. – cardiff space man Nov 13 '15 at 01:02

3 Answers3

9

UPDATED

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:

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME
export PATH

Save and reboot.

Test your Java installation:

java -version
David Foerster
  • 36,264
  • 56
  • 94
  • 147
Egidijus
  • 106
  • 1
  • 5
  • 1
    This worked for me. The only change I made was to add a symlink from the current jdk directory /usr/lib/jvm/jdk1.7.0_45 to the generic location: /usr/lib/jvm/java-7-oracle

    This way one doesn't have to update the path in /etc/profile (and in possible other application locations) every time the JDK is updated. Also many programs (e.g. elasticsearch) look for java at /usr/liv/jvm/java-7-oracle as one of the default locations.

    – Ville Mar 22 '14 at 06:51
2

Very old stuff, but if some one is lookig for this yet, just install openjdk-7-jre-headless or openjdk-6-jre-headless

-1

I think this is not a good idea to skip any dependency when installing from source. You can't skip this all time. When you update dependency using apt-get it will be check there also.

Nabil
  • 2,142