Question
What is the correct target for the JAVA_HOME environment variable for a Linux OpenJDK Debian-based distribution?
Answer
Configuring the JAVA_HOME environment variable correctly in a Debian-based distribution, such as Kubuntu, is essential for running Java applications smoothly, especially when dealing with different file locations for executables and libraries.
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
# Add JAR files manually if needed
export CLASSPATH=$JAVA_HOME/lib/*
Causes
- Java executables are located in `/usr/bin`
- Java libraries (JAR files) are stored in `/usr/share/java`
Solutions
- Set JAVA_HOME to `/usr/lib/jvm/java-*`, where `*` matches your installed OpenJDK version.
- Ensure that the necessary binary paths are included in your system's PATH variable.
Common Mistakes
Mistake: Setting JAVA_HOME to `/usr` or `/usr/share/java` directly.
Solution: JAVA_HOME should point to the JDK installation path like `/usr/lib/jvm/java-11-openjdk-amd64`.
Mistake: Not including JAVA_HOME/bin in the PATH variable.
Solution: Make sure to add `export PATH=$JAVA_HOME/bin:$PATH` to your `.bashrc` or `.bash_profile`.
Helpers
- JAVA_HOME Linux
- OpenJDK Debian
- JAVA_HOME setup
- Debian Java configuration
- configure JAVA_HOME Linux