How can I set JAVA_HOME on Ubuntu 14.04?

Published on Author Code Father
How can I set JAVA_HOME on Ubuntu 14.04?

There are two common places where you can put the JAVA_HOME variable:

  • ~/.bashrc
  • ~/.profile

The difference is that the first file is run when you start a terminal. This makes sense because most programs that you need to use when you program in Java are command line tools (Gradle, Maven). However, sometimes you need to start a Java-based GUI program without opening a terminal (for example, by clicking on its shortcut on desktop). If it requires JAVA_HOME, chances are it will not work. That’s why defining JAVA_HOME in .profile is better in these situations.

You usually want to have java and javac available, so you should define JAVA_HOMEand add the bin directory to the PATH. This is how:

  1. JAVA_HOME=/usr/lib/jvm/java8openjdkamd64