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

58,724

Solution 1

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

Solution 2

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

Share:
58,724

Related videos on Youtube

Dr.Haribo
Author by

Dr.Haribo

Updated on September 18, 2022

Comments

  • Dr.Haribo
    Dr.Haribo over 1 year

    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.

    • Admin
      Admin almost 11 years
      Does it help if you add the --no-install-recommends option?
    • Admin
      Admin almost 11 years
      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.
    • Admin
      Admin almost 11 years
      @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.
    • Admin
      Admin almost 11 years
      @gertvdijk Got it. Then I think this is a bug. There should be a openjdk-7-jdk-headless package.
    • Admin
      Admin almost 11 years
    • Admin
      Admin over 10 years
      @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.
    • Admin
      Admin over 10 years
      @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.
    • Admin
      Admin over 8 years
      --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.
  • gertvdijk
    gertvdijk almost 11 years
    "when installing from source" OP isn't installing from source.
  • Ville
    Ville about 10 years
    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.
  • David Foerster
    David Foerster over 9 years
    The question is asking specifically about version 7.
  • Dr.Haribo
    Dr.Haribo over 9 years
    jre != jdk there's no jdk-headless
  • ThisGuy
    ThisGuy almost 8 years
    Except not: "openjdk-8-jre-headless" depends on "libx11-6" in 16.04, this ends up pulling in the whole of X11.