Search code examples
ubuntuenvironment-variablesjava-hometcserver

How to fix "The JAVA_HOME environment variable is not defined" in Ubuntu Server


I'm trying to set up a java web app, and I keep getting the error The JAVA_HOME environment variable is not defined. Here is what I'm trying to do:

user: /dir... $ /opt/pivotal/pivotal-tc-server-standard-3.1.3.SR1/tcruntime-instance.sh create myserver

Then I get this error:

The JAVA_HOME environment variable is not defined

What I've tried to do:

~Set the environment variable in /etc/environment. I opened /etc/environment with sudo nano, and added the following, JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64".

~Set the environment variable in /etc/profile. I opened /etc/profile with sudo nano, and added the following, export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64", then export PATH=$JAVA_HOME/bin:$PATH.

Neither of these solutions worked. This seems like an easy fix, but I must be overlooking something. Any suggestions?


Solution

  • Have a look at this.

    Execute "source /etc/environment" in every shell where you want the variables to be updated:

    $ source /etc/environment
    

    If you want to set JAVA_HOME environment variable in only the terminal, set it in ~/.bashrc file.

    EDIT: In the case of the original post, all that needed to be done was to reboot the server.