2

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?

erip
  • 16,374
  • 11
  • 66
  • 121
aCarella
  • 2,369
  • 11
  • 52
  • 85
  • 1
    No need to add PATH. Did you start a new terminal after changes? – alpert May 15 '16 at 20:57
  • 1
    I'd put it in my .bashrc, .profile, or .bash_profile; did you log out and log in after making the change? – David Conrad May 15 '16 at 20:58
  • using sudo to edit profile could be an issue. see this for more details: http://askubuntu.com/questions/707539/setting-system-wide-environment-variable-using-etc-environment – Vijay May 15 '16 at 21:02
  • Silly. Restarting my server allowed this to work. If you put this as an answer I'll mark it as such. Thanks. – aCarella May 15 '16 at 21:15
  • 1
    @aCarella: Restarting your server is probably overkill. You just need to update the environment in each running process where you need the new settings. Logging out without actually restarting the system will do this -- but even that shouldn't be necessary. On the other hand, restarting is a good way to verify that the changes you've made are persistent. – Keith Thompson May 16 '16 at 20:10

1 Answers1

1

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.

Community
  • 1
  • 1
sebenalern
  • 2,515
  • 3
  • 26
  • 36