1. find /usr/lib/jvm/java-1.x.x-openjdk
  2. vim /etc/profile

    Prepend sudo if logged in as not-privileged user, ie. sudo vim

  3. Press 'i' to get in insert mode
  4. add:

    export JAVA_HOME="path that you found"
    
    export PATH=$JAVA_HOME/bin:$PATH
    
  5. logout and login again, reboot, or use source /etc/profile to apply changes immediately in your current shell
Answer from That Dave Guy on Stack Overflow
๐ŸŒ
NTU Singapore
www3.ntu.edu.sg โ€บ home โ€บ ehchua โ€บ programming โ€บ howto โ€บ Environment_Variables.html
Environment Variables for Java Applications - PATH, CLASSPATH, JAVA_HOME
Environment variables are global system variables accessible by all the processes/users running under the Operating System (OS), such as Windows, macOS and Linux.
๐ŸŒ
Medium
medium.com โ€บ @noah24.kim โ€บ how-to-set-java-environment-variable-in-ubuntu-4244311211ad
How to set Java environment variable in Ubuntu | by Noah T. K | Medium
April 23, 2023 - Now, add this Java path to the PATH variable in order to use Java. export PATH=$PATH:$JAVA_HOME/bin echo $PATH Then you will see the PATH variable which added Java path. ... Now you are done with setting up Java environment variable.
๐ŸŒ
Helical Insight
helicalinsight.com โ€บ home โ€บ blog โ€บ configure java_home/jre_home environment variables for linux
Configure JAVA_HOME/JRE_HOME Environment Variables For Linux
February 16, 2026 - export JAVA_HOME=/usr/lib/jvm/java-25-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH ... If it returns the just set path, the environment variable has been set successfully.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ setting-environment-java
Setting up Environment Variables For Java - Complete Guide to Set JAVA_HOME - GeeksforGeeks
May 9, 2025 - Go inside System Variables section, select the path variable. Right-click on it and choose the option Edit. In the Edit environment window, click New. ... Then add the path to the JDK's bin folder (e.g., C:\Program Files\Java\jdk-23\bin). ... Click OK to save the changes. Now to verify the installation, open command Prompt and run the below commands: ... If you are Linux user then find the complete solution to setting up environment variables for Java on Linux operating system.
Find elsewhere
๐ŸŒ
Java67
java67.com โ€บ 2016 โ€บ 06 โ€บ how-to-set-javahome-and-path-in-linux.html
How to set JAVA_HOME and PATH in Linux? Example | Java67
Java developers like me always set mandatory environment variables like JAVA_HOME, PATH, and CLASSPATH on the login scripts executed by the shell when you log in to Linux like bash_profile.sh, but you can also set JAVA_HOME into /etc/profile ...
๐ŸŒ
Oracle
java.com โ€บ en โ€บ download โ€บ help โ€บ path.html
How do I set or change the PATH system variable?
Click Environment Variables. In the section System Variables find the PATH environment variable and select it.
๐ŸŒ
nixCraft
cyberciti.biz โ€บ nixcraft โ€บ howto โ€บ bash shell โ€บ how to set java_home / path variables under linux bash profile
How to Set JAVA_HOME / PATH variables Under Linux Bash Profile - nixCraft
May 25, 2012 - I installed jre-7 beat onto /opt .I appended the PATH of bin of java to /etc/environment variable and it works. ... java_vm throws out error โ€œjava_vm process: could not find Java VM symbolsโ€ ,Any Idea how to set PLUGIN_HOME variable for a jre 7 install(manually installed from jar archive) ... Hi , set JAVA_HOME and PATH variables for every user under my Linux system(ubuntu 10.04) open profile $sudo vi /etc/profile; insert into last line: #set java environment JAVA_HOME=/usr/lib/jvm/java-6-sun // I am using jdk1.6.0.20 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar PATH=$PATH:$JAVA_HOME/bin export JAVA_HOME export CLASSPATH export PATH export GDK_NATIVE_WINDOWS=true #this is for setting eclipse #env GDK_NATIVE_WINDOWS=1 #me too!
๐ŸŒ
Cleverence
cleverence.com โ€บ articles โ€บ oracle-documentation โ€บ java-environment-variables-and-path-5821
Java Environment Variables: Configure JAVA_HOME, PATH, and CLASSPATH on Windows, macOS, and Linux
March 13, 2026 - On Linux servers, service managers like systemd let you set Environment=JAVA_HOME=/opt/jdk-21 and EnvironmentFile entries in unit files.
๐ŸŒ
Cleverence
cleverence.com โ€บ articles โ€บ oracle-documentation โ€บ setting-an-environment-variable-for-java-5824
How to Set Java Environment Variables (JAVA_HOME, PATH) on Windows, macOS, and Linux
May 3, 2026 - Linux offers both package-managed OpenJDK and vendor-specific distributions. For per-user settings, export variables in your shell rc file (~/.bashrc for Bash, ~/.zshrc for Zsh). For system-wide settings, prefer profile scripts like /etc/profile.d/java.sh so non-interactive services pick up JAVA_HOME and PATH consistently. ... For services launched by systemd, environment files and unit overrides are often cleaner than global variables.
๐ŸŒ
Twilio
twilio.com โ€บ en-us โ€บ blog โ€บ developers โ€บ community โ€บ working-with-environment-variables-in-java
Setting Environment Variables in Java | Twilio
June 11, 2025 - If the environment variable that your code needs is one of the ones defined by your operating system, such as %COMPUTERNAME% by Microsoft Windows or $HOME on Linux, macOS, and FreeBSD, then no. Otherwise, yes, they need to be set either by your code, or by the process that launches your Java application.
๐ŸŒ
Oracle
docs.oracle.com โ€บ cd โ€บ F74770_01 โ€บ English โ€บ Installing โ€บ p6_eppm_install_config โ€บ 89522.htm
Setting an Environment Variable for Java
February 2, 2024 - In the Variable value field, insert %JAVA_HOME%\bin; in front of all the existing directories. Do not delete any existing entries; otherwise, some existing applications may not run. ... Exit the Control Panel. Setting the Environment Variables with Unix or Linux
Top answer
1 of 4
1

Using 12.04, placing the information in /etc/environment worked for me:

tku@buster:~$ cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
[...]
LC_MEASUREMENT="de_DE.UTF-8"
JAVA_HOME=/home/tku/work/jdk1.7.0_05
2 of 4
1

You wanna make sure your Java is the default:

Set Default Java Version

Use the alternatives command to set the default java version.

~ ~โ†“โ†“$โ†“โ†“ sudo alternatives --config java

Select Java:

If your system has multiple Java versions, the above command will list all Java versions.

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
 + 1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-4.fc35.x86_64/bin/java)
   2           java-latest-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.1.0.12-2.rolling.fc35.x86_64/bin/java)
*  3           /usr/java/jdk-17.0.1/bin/java

Enter to keep the current selection[+], or type selection number: whateverisyours


Verify Java Version

Check the java version using the following command.

~ ~โ†“โ†“$โ†“โ†“ java --version

output feks.:

java 18.0.2 2022-07-19
Java(TM) SE Runtime Environment (build 18.0.2+9-61)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing)

Then, add the required variables.

To set the environment variables for a particular user, place the below variables in the .bash_profile file in the home directory or in the /etc/environment file for system wide settings.

~ ~โ†“โ†“$โ†“โ†“ sudo nano /etc/environment

and your information there is current version of Java:

export PATH=$PATH:/usr/java/jdk-18.0.2/bin/
export JAVA_HOME=/usr/java/jdk-18.0.2/  

if your using JRE then it will look something like this:

export PATH=$PATH:/usr/java/jre*****/bin/
export JAVA_HOME:/usr/java/jre*****/

Test it by executing:

~ ~โ†“โ†“$โ†“โ†“ echo $JAVA_HOME
~ ~โ†“โ†“$โ†“โ†“ echo $PATH
~ ~โ†“โ†“$โ†“โ†“ java --version