Installing Oracle’s JDK on Debian/Ubuntu

Due to licensing issues, Linux distributions don’t ship Oracle Java packages anymore. In many cases, that doesn’t matter since you can just use OpenJDK. But if you do need Oracle’s JDK, Debian packages are a bit more convenient than handling tarballs because they integrate nicely with the rest of the system. Fortunately, there’s a simple way of creating a Debian package from the official JDK using the java-package tool.

In Ubuntu, java-package is available from the multiverse repository. On desktop systems, the repository is usually enabled, while on some server systems you may have to enable it yourself. Here’s how I did that on an Ubuntu 14.04 LTS machine:

$ cat /etc/apt/sources.list.d/ubuntu-multiverse.list
deb trusty multiverse
deb trusty-updates multiverse
deb trusty-backports multiverse
deb trusty-security multiverse

After you’ve created the file, you can install the package we need:

$ sudo apt-get update
$ sudo apt-get install java-package

Now download the official .tar.gz distribution from Oracle’s Java portal. For most people, it’s the 64-bit version, ie. jdk-8u25-linux-x64.tar.gz.

Run the make-jpkg tool to create the .deb file. There are a few command line switches for setting package metadata (see the man page for more information), but they are optional:

$ make-jpkg jdk-8u25-linux-x64.tar.gz

An interactive wizard will ask you to confirm the licensing agreement and after a minute or so you should find the newly created package in a file named oracle-java8-jdk_8u25_amd64.deb that you can install on as many systems as you like.

After installing the package, verify that it’s active:

$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

If you have multiple JDKs installed, you can switch between them using the update-java-alternatives utility. To do this, you’ll need the list of installed JDKS:

$ update-java-alternatives -l
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64
jdk-8-oracle-x64 318 /usr/lib/jvm/jdk-8-oracle-x64

Pick the JDK you want from the list and activate it:

$ sudo update-java-alternatives -s jdk-8-oracle-x64

After that, run java -version again and the JDK you selected should be active. Note that when using Debian’s alternatives mechanism, there is usually no need to set the $JAVA_HOME environment variable or to change your $PATH.

Posted in java | Tagged , , | Leave a comment

Managing Docker Container Updates

When running a Debian/Ubuntu-based server, it’s relatively easy to figure out whether updates need to be installed. Tools based on apt work very well in this regard and even offer advanced features like unattended updates. Not so with services running in Docker containers.

Continue reading

Posted in linux | Tagged , , | Leave a comment

Converting Images to ASCII Art

I’ve been playing with Docker a lot lately. Docker is a tool for creating lightweight virtual environments based on Linux containers. They are extremely useful for running services, but you can also use them for running one-off tasks that you don’t want to run on the host system directly. Since a container shares the host machine’s kernel, startup is instantaneous and there’s no extra memory footprint. Think of Linux containers as generalized chroot environments or as extremely lightweight virtual machines.

Continue reading

Posted in linux | Tagged , , | Leave a comment

Maven: Discovering Dependency Conflicts

Among other things, Maven’s dependency plugin displays the result of Maven’s dependency resolution mechanism. The output of the dependency:tree goal makes it easy to see where transitive dependencies come from. This week I discovered that recent versions of the plugin also support a verbose flag that lists conflicts and shows how Maven resolved them.

Continue reading

Posted in java | Tagged , , | Leave a comment

Testing equals() with Guava

I’ve long held the opinion that Guava belongs on every Java classpath because its design and the quality of its implementation surpass other comparable utility libraries (and sometimes even the JDK). Guava’s testlib is pretty cool, too, even though it’s not as widely known.

Continue reading

Posted in java | Tagged , , , | Leave a comment

Enabling Hibernate Support in Ubuntu 14.04 LTS

In this article, I’ll show you how to enable hibernate support in Ubuntu 14.04 (“Trusty Tahr”) by making a “Hibernate” menu entry appear in Unity’s global system pulldown menu. The Ubuntu developers disabled this a couple of years ago because hibernate didn’t work reliably on all systems – proceed at your own risk!

Continue reading

Posted in linux | Tagged , | 8 Comments

Google Music

My Nexus 4 and 7 devices don’t ship with an old school MP3 player anymore. After trying lots and lots of players (all of which I didn’t like), I ended up with Google Music, which is pre-installed on all Nexus devices. While its queue handling takes some getting used to, the player works well and looks really great if your MP3s have embedded album art. I had always wanted off-premises backup for my music, so when I read that you can upload 20,000 songs for free, I decided to give it a try with my own MP3s.

Continue reading

Posted in misc | Tagged , , | Leave a comment