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:
pkg update
pkg upgrade
Optionally install common tools:
pkg install -y vim wget
2. Check whether Java is installed
java -version
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:
pkg search -o openjdk17
Install the JDK:
pkg install -y openjdk17
4. Verify the installation (java + javac)
Verify the runtime:
java -version
Verify the compiler (JDK presence):
javac -version
5. Test Java 17 with a simple program
Create a working directory:
mkdir -p simple-app
cd simple-app
Create Simple.java:
vim Simple.java
Use this code:
public class Simple {
public static void main(String[] args) {
System.out.println("Java 17 is installed properly");
}
}
Compile:
javac Simple.java
Run:
java -cp . Simple
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:
/usr/local/openjdk17/bin/java -version
/usr/local/openjdk17/bin/javac -version
If your installation path differs, locate it with:
pkg info -l openjdk17 | rg '/bin/(java|javac)$'
Option B: adjust PATH for your shell session
export PATH="/usr/local/openjdk17/bin:$PATH"
java -version
7. Configure environment variables (JAVA_HOME + PATH)
- Confirm where
javacis:
which javac
- Set
JAVA_HOME(commonly/usr/local/openjdk17).
For sh/bash:
echo 'export JAVA_HOME=/usr/local/openjdk17' >> ~/.profile
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.profile
. ~/.profile
For csh/tcsh, update ~/.cshrc instead:
setenv JAVA_HOME /usr/local/openjdk17
setenv PATH "$JAVA_HOME/bin:$PATH"
Verify:
echo $JAVA_HOME
java -version
javac -version
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:
java -version
javac -version
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/