How to add JAVA_HOME on Ubuntu?
On Ubuntu, we can add
JAVA_HOME environment variable in
/etc/environment system-wide environment variable settings, which means all users use it. It is not a script file, but rather consists of assignment expressions, one per line. We need admin or sudo to modify this it.
Further Reading Ubuntu – EnvironmentVariables
/etc/environment file with a text editor like vim or nano, need root or sudo.
$ sudo vim /etc/environment
JAVA_HOME at the next line, and points to a specified JDK folder directly.
1.3 Reflect the changes in the current session.
$ source /etc/environment $ echo $JAVA_HOME /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64
The new changes will disappear if we close the current session or reopen a new terminal because a new shell does not trigger the
/etc/environment. Try to restart the Ubuntu or login again; the new changes in
/etc/environment will apply automatically.
- How to install Java JDK on Ubuntu
- Setting PATH variable in /etc/environment vs .profile
- Ubuntu – EnvironmentVariables