Adding JAVA_HOME in Ubuntu

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.

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

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

    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.