Remember: If you ever need to switch between Java versions (e.g., Java 11 for an older project), tools like jEnv (macOS/Linux) or the "Java Version Manager" for Windows can help.
export JAVA_HOME=$(/usr/libexec/java_home) # macOS only # OR for Linux: export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH Then reload: source ~/.bashrc Create a simple Java program to confirm everything works. Save the following as Test.java : installing java 17
javac Test.java java Test Expected output: Remember: If you ever need to switch between
public class Test public static void main(String[] args) System.out.println("Java 17 is running successfully!"); System.out.println("Version: " + System.getProperty("java.version")); Java 11 for an older project)
Add this to your ~/.bashrc , ~/.zshrc , or ~/.profile file:
Compile and run:
echo %JAVA_HOME% If empty, add it manually via System Properties > Environment Variables.