This guide shows you how to install OpenJDK 17 on FreeBSD 13, verify both the runtime (java) and the compiler (javac), configure JAVA_HOME and PATH, and troubleshoot common problems.
Java (and the JVM) is required by many services and tools such as Tomcat, Jetty, GlassFish, Cassandra, and Jenkins.
Related guides:
- How to Install Java 17 in OpenSUSE Leap 15.3
- How to Install Java 17 in Fedora 35
- How to Install Java 17 in Debian 11
- How to Install Java 17 in Ubuntu 20.04
- How to Install Java 17 on Rocky Linux / CentOS 8
Prerequisites
- An up-to-date FreeBSD 13 system
- Root access (or a user with
sudo) - Internet access
1. Update FreeBSD packages
Run:
| |
Optionally install common tools:
| |
2. Check whether Java is installed
| |
If you get java: Command not found, Java is not installed (or PATH is not set correctly).
3. Install OpenJDK 17
OpenJDK 17 is available in the default FreeBSD 13 repositories.
Search for the package:
| |
Install the JDK:
| |
4. Verify the installation (java + javac)
Verify the runtime:
| |
Verify the compiler (JDK presence):
| |
5. Test Java 17 with a simple program
Create a working directory:
| |
Create Simple.java:
| |
Use this code:
| |
Compile:
| |
Run:
| |
You should see:
Java 17 is installed properly
6. Toggling multiple Java versions (explicit paths or PATH)
If you install multiple OpenJDK versions, avoid guessing which one java points to.
Option A: use explicit paths
For example, check:
| |
If your installation path differs, locate it with:
| |
Option B: adjust PATH for your shell session
| |
7. Configure environment variables (JAVA_HOME + PATH)
- Confirm where
javacis:
| |
- Set
JAVA_HOME(commonly/usr/local/openjdk17).
For sh/bash:
| |
For csh/tcsh, update ~/.cshrc instead:
| |
Verify:
| |
8. Troubleshooting
java: Command not found
- Confirm OpenJDK is installed:
pkg info openjdk17 - Check what
javapoints to:which java - Confirm
PATH:echo $PATH
javac: Command not found
You likely installed only a JRE (runtime) package or your PATH is pointing to the wrong Java installation. Install/verify the JDK with openjdk17.
Build tools use the wrong Java version
Always print both versions in your build steps:
| |
Conclusion
You now have OpenJDK 17 installed on FreeBSD 13, verified with java and javac, and (optionally) configured for typical JAVA_HOME/PATH workflows.
For more details, refer to the official Java documentation: https://docs.oracle.com/en/