[java] How to set JAVA_HOME path on Ubuntu?

How can I setup JAVA_HOME path without having to set it each time I restart my machine?

I've used the following ways when trying to set JAVA_HOME on my Ubuntu machine:

1) From terminal I've executed the following command:

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0

2) I've edited the /etc/enviroment file directly to add JAVA_HOME path in it

What's really strange is that if I test JAVA_HOME using the echo command after an of the above two ways, I can see it is set correctly, but if I restart, logout/ login again or even after working on the machine for a while the JAVA_HOME is no more set and I have to set it again using any of the above two ways.

So can someone please tell me what I am doing wrong here?

This question is related to java linux ubuntu java-home

The answer is


add JAVA_HOME to the file:

/etc/environment

for it to be available to the entire system (you would need to restart Ubuntu though)


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to linux

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt?

Examples related to ubuntu

grep's at sign caught as whitespace "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? "Repository does not have a release file" error ping: google.com: Temporary failure in name resolution How to install JDK 11 under Ubuntu? How to upgrade Python version to 3.7? Issue in installing php7.2-mcrypt Install Qt on Ubuntu Failed to start mongod.service: Unit mongod.service not found

Examples related to java-home

Set ANDROID_HOME environment variable in mac Error: JAVA_HOME is not defined correctly executing maven How to set JAVA_HOME in Linux for all users Android Studio error: "Environment variable does not point to a valid JVM installation" Installing Android Studio, does not point to a valid JVM installation error How can I change Mac OS's default Java VM returned from /usr/libexec/java_home How to set JAVA_HOME path on Ubuntu? Where is the Java SDK folder in my computer? Ubuntu 12.04 How to set JAVA_HOME in Mac permanently? How to set CATALINA_HOME variable in windows 7?