How to set default Java version in Ubuntu

The Ubuntu archives have multiple versions of OpenJDK available. One of these is designated as the default and this has the package names default-jdk and default-jre. The java and javac programs will be symlinked to the binaries from this default JDK. On my Ubuntu, the default packages were linked to the openjdk-7-jdk and openjdk-7-jre packages.

However, you might want to install and use other versions of JDK. For example, to use Java 8 I did:

$ sudo apt install openjdk-8-jdk

The problem is that java, javac and other binaries still point to the default Java version. To switch the default Java binaries, use the update-java-alternatives tool.

  • To list the Java versions installed on your system, use the --list option:
$ update-java-alternatives --list
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
  • To set one of the above Java versions as the default, use the --set option:
$ sudo update-java-alternatives --set java-1.8.0-openjdk-amd64

Tried with: Ubuntu 14.04

How to fix font of IntelliJ

Before and after fixing font in Android Studio
Before and after fixing font in Android Studio

Problem

IntelliJ and other tools based on it, like Android Studio, look terrible on Ubuntu 14.04 with OpenJDK 7. The font rendering in the UI is terribly aliased and is a pain on the eyes. This is surprising since Eclipse renders beautifully using the same JDK and Ubuntu system.

Solution

Eclipse uses GTK for its GUI while IntelliJ and Android Studio use Swing. Thankfully, this situation can be fixed.

  • Replace the OpenJDK with a version in which font rendering has been fixed:
$ sudo apt-get purge openjdk-7-jdk
$ sudo add-apt-repository ppa:no1wantdthisname/openjdk-fontfix
$ sudo apt-get update
$ sudo apt install openjdk-7-jdk
  • Open the studio64.vmoptions file and change the anti-aliased font setting to -Dawt.useSystemAAFontSettings=on. Other options suggested by users online did not work for me.

Now IntelliJ or Android Studio should render the font much better. I still notice a bit of aliasing with Consolas, but it is manageable.

Tried with: Android Studio 1.4 and Ubuntu 14.04