Installationeasy0-2 years

`java -version` reports 21. `javac -version` reports 17. The build fails with errors about syntax that is definitely valid Java 17 and definitely legal in 21. What's actually going on, and why are `PATH` and `JAVA_HOME` both part of the answer?

Two JDKs are installed, and java and javac are resolving to different ones. PATH is an ordered list of directories the shell searches for a bare command name, and it uses the first match — so if a Java 21 install's bin/ comes before a Java 17 install's bin/ in PATH, but something else (an IDE setting, an older shell alias, a build tool reading JAVA_HOME) still points javac at the Java 17 install, the two commands quietly disagree. It looks like a language problem — the error messages complain about syntax — and is actually a directory-order problem: fix it by setting JAVA_HOME to the JDK you actually want and putting $JAVA_HOME/bin first in PATH, so both java and javac come from the same installation.

The lesson behind it →