I have been trying to figure out the best way to run OpenJDK Java Runtime as default Java for my Fedora box and use Oracle JDK 6 for Android development namely for running Android SDK Manager, Android Studio and Eclipse from Android Bundle.

I installed OpenJDK Java Runtime from the Fedora repository which has setup alternatives as follow.

[donnie@fedora ~]$ alternatives --list | grep java
jre_openjdk             auto    /usr/lib/jvm/java-1.7.0-openjdk-
jre_1.7.0               auto    /usr/lib/jvm/java-1.7.0-openjdk-
java                    auto    /usr/lib/jvm/java-1.7.0-openjdk-
libjavaplugin.so.x86_64 auto    /usr/lib64/IcedTeaPlugin.so

I have installed the Oracle JDK 6 using the rpm provided by Oracle.

I could make Android Bundle and Studio make use of JAVA_HOME to run under Oracle JDK by sticking following in .bashrc.

export JAVA_HOME=/usr/java/jdk1.6.0_45/
export PATH=$JAVA_HOME/bin:$PATH

I noticed that Chrome still uses OpenJDK (as I still need to link the plugin).

What are the difference between JAVA_HOME and using alternatives?

1 Answer 1



Alternatives is a tool that will manage the locations of the installed software using links under the control of the alternatives tool.

These links are ultimately managed under /etc/alternatives with intermediate links created under a directory in $PATH, typically /usr/bin.


$ ls -l /usr/bin/java
lrwxrwxrwx. 1 root root 22 Feb 24 17:36 /usr/bin/java -> /etc/alternatives/java

$ ls -l /etc/alternatives/java
lrwxrwxrwx. 1 root root 73 Feb 24 17:36 /etc/alternatives/java -> /usr/lib/jvm/java-1.7.0-openjdk-


$JAVA_HOME is where software can be told to look through the use of an environment variable. Adding it to the $PATH simply adds the executables present in $JAVA_HOME/bin to your $PATH. This is sometimes necessary for certain applications.

The 2 mechanisms are related but can be used together or independent of each other, it really depends on the Java application which mechanism is preferable.

What I do

I typically use $JAVA_HOME for some GUI applications, but in general use it only for server installations that make use of Jetty, Tomcat, or JBOSS, for example.

For these installations I'll still use alternatives to manage the Java installations prior to setting the $JAVA_HOME. I like doing it this way in cases where I might need to have multiple installations of Java.

Alternatives does allow you to have certain tools use one installation of Java while other tools use a completely different one.


  • The giveaway is that with alternatives I can use different components of Java. For example, Alternatives can set java and javac from different JDKs on the other hand JAVA_HOME=JAVALOCATION would point java, javac, and javaws to java, javac and javaws in JAVALOCATION, respectively. Apr 7, 2014 at 5:49
  • The reason I asked this question was how can I use OpenJDK as default Java Runtime and make Android Studio, Eclipse and SDK Manager use Oracle JDK. I can run those three programs under Oracle JDK by hard editing their startup scripts which might get broken if they are updated. I was looking for something more generic like STUDIO_JDK, that I can add to ~/.profile or ~/.bashrc, that is used by Android Studio for picking up JDK but I think Android Bundle (Eclipse and SDK Manager) won't honor that. Apr 7, 2014 at 5:56
  • @donniezazen - yeah STUDIO_JDK is a custom thing. I would use alternatives for those tools and set JAVA_HOMEto the path under /usr/bin which is managed by alternatives. When upgrades are performed, changing alternatives is all that's required.
    – slm
    Apr 7, 2014 at 11:45
  • I am not sure what you are proposing. Point both alternatives and JAVA_HOME to say /usr/bin/java. Also it seems like JAVA_HOME overrides alternatives. Apr 7, 2014 at 12:23
  • @donniezazen - yes use alternatives to manage your JAVA installs and then use JAVA_HOME, pointing it to /usr/bin. You're correct, JAVA_HOME can operate independently from alternatives.
    – slm
    Apr 7, 2014 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .