Ubuntu – Problem in setting JAVA_HOME variable


I have installed JDK on path /usr/lib/jvm/java-8-oracle.
To set JAVA_HOME variable, I opened /etc/environment in gedit and added :

JAVA_HOME="/usr/lib/jvm/java-8-oracle" to it.

But I got error while saving it as :

Could not save the file “/etc/environment”.
You do not have the permissions necessary to save the file. Please check   that you typed the location correctly and try again.

Where is it going wrong? How do I set JAVA_HOME variable?

Best Answer

You can do this by adding

export JAVA_HOME="/usr/lib/jvm/java-8-oracle"

to your .bashrc file. You can do this by using the following steps:

  1. press ctrl+alt+T to open a terminal
  2. type gedit ~/.bashrc
  3. add export JAVA_HOME="/usr/lib/jvm/java-8-oracle" ad the end of the file.
  4. save the changes
  5. type source ~/.bashrc to apply the changes to your current session.

The error message you got means that you don't have permissions to change the /etc/environment file. This should be possible, using sudo.

Related Question