This short article shows how to change used Java installation on a Windows or Linux system.
On Windows 10
Use the search bar for "environment variables" and choose the result with system variables. It will open 'System Properties' dialog at the 'Advanced' tab.
Press 'Environment variables' button.
Check for 'JAVA_HOME' variable existence in the list. If it doesn't exist, then create it and paste the path to desired Java
installation, otherwise edit it and paste a different path. It can look like "C:\Users\alexiy\.jdks\corretto-16.0.2".
Press OKs. Open command prompt or Powershell and check the Java version by running "java -version".
On Windows 7
Open environment variables window (by right-clicking "Computer" icon, selecting "Advanced system properties", then selecting "Advanced" tab, and pressing "Environment variables" button).
Check "JAVA_HOME" variable for existence in the "System variables" list. If it doesn't exist, create it
(paste the desired Java installation path in the "Variable value" field),
otherwise, just change the value accordingly. The path can look like
"C:\Users\Alexiy\openjdk-14.0.1_windows-x64_bin\jdk-14.0.1".
Check the "Path" variable for other existing Java paths - you will have to press "Edit" and scroll the value
text field all the way to the left by the arrow key. If you encounter
previous Java mentions, then you must place the Java home variable before them; do it by writing "%JAVA_HOME%\bin;".
Press OKs to apply changes and close the dialogs.
Open a new command prompt and run "java -version". It should show the new Java version if everything was
done correctly.
On Linux
Edit /etc/profile to include line export JAVA_HOME="/absolute/path/to/jre/directory"
Write that line before export PATH=...
Make sure that export PATH=... line includes $JAVA_HOME/bin part and looks like export
PATH=$JAVA_HOME/bin:$PATH.
Save the file and restart the system. Test with "java -version".