3

I installed ImageJ (sudo apt install imagej) on Ubuntu 16.04, but it does not work:

$ imagej
Open other images in this ImageJ panel as follows:
  imagej -p 1 <image1> [<image2> ... <imageN>]

No JVM found to run ImageJ
Please apt-get install a JVM to run ImageJ or 
set JAVA_HOME if it's not a JVM from a Debian Package.

However, OpenJDK 8 is installed:

$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

What should I do to get ImageJ running?

Byte Commander
  • 110,243

1 Answers1

3

This is a bug. It's Reported at launchpad here titled imagej won't start (xenial). Which is itself a duplicate of this bug, which says JAVA_HOME auto-detection fails due to whitespace in update-java-alternatives output

It is fixed in Debian and fixed version is included in Yakkety.

There are several fixes reported in the bug report. One fix that worked for me was manually exporting JAVA_HOME and starting from terminal

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
imagej

Someone reported that a build of Yakkety works for Xenial too. It can be downloaded from here https://launchpad.net/ubuntu/+source/imagej/1.50i+dfsg-1/+build/9642507

I downloaded that build and it works without any workaround!


Another workaround is directly editing /usr/bin/imagej file as suggested by ByteCommander (Thanks to him). Around line 32, changing the line

JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | cut -d' ' -f 3)

to

JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | grep openjdk | sort | tail -1 | tr -s ' ' | cut -d' ' -f 3)

that is basically inserting tr -s ' ' | before cut ...

Anwar
  • 77,855