Adding JAVA_HOME in Ubuntu

Background

I’ve been using Linux (specifically Ubuntu) for quite some time now, I’ve been trying to migrate to Linux from Windows. One of the first thing I’ve encountered is adding an environment variable. Compared to Windows, its very similar, only that you have multiple ways to do it. One way I find to be the easiest is by adding it to /etc/environment file. So here’s how to do it.

Steps

  1. Open /etc/environment as root in GEdit (or any text editor you have)

    1
    sudo gedit /etc/environment
  2. Add the following lines (remember to change the version to what you are also using).

    1
    JAVA_HOME="/usr/lib/jvm/java-1.5.0-sun"
  3. Save it and log-off or restart you machine, that’s it!

You can also add other variables like your MAVEN_HOME or anything you want.