How to Install Java 17 on FreeBSD 13 (OpenJDK)

Complete step-by-step guide to install OpenJDK 17 on FreeBSD 13 using pkg, verify with java and javac, configure JAVA_HOME and PATH, and troubleshoot common errors.

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:

Prerequisites

  • An up-to-date FreeBSD 13 system
  • Root access (or a user with sudo)
  • Internet access

1. Update FreeBSD packages

Run:

1
2
pkg update
pkg upgrade

Optionally install common tools:

1
pkg install -y vim wget

2. Check whether Java is installed

1
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:

1
pkg search -o openjdk17

Install the JDK:

1
pkg install -y openjdk17

4. Verify the installation (java + javac)

Verify the runtime:

1
java -version

Verify the compiler (JDK presence):

1
javac -version

5. Test Java 17 with a simple program

Create a working directory:

1
2
mkdir -p simple-app
cd simple-app

Create Simple.java:

1
vim Simple.java

Use this code:

1
2
3
4
5
public class Simple {
  public static void main(String[] args) {
    System.out.println("Java 17 is installed properly");
  }
}

Compile:

1
javac Simple.java

Run:

1
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:

1
2
/usr/local/openjdk17/bin/java -version
/usr/local/openjdk17/bin/javac -version

If your installation path differs, locate it with:

1
pkg info -l openjdk17 | rg '/bin/(java|javac)$'

Option B: adjust PATH for your shell session

1
2
export PATH="/usr/local/openjdk17/bin:$PATH"
java -version

7. Configure environment variables (JAVA_HOME + PATH)

  1. Confirm where javac is:
1
which javac
  1. Set JAVA_HOME (commonly /usr/local/openjdk17).

For sh/bash:

1
2
3
echo 'export JAVA_HOME=/usr/local/openjdk17' >> ~/.profile
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.profile
. ~/.profile

For csh/tcsh, update ~/.cshrc instead:

1
2
setenv JAVA_HOME /usr/local/openjdk17
setenv PATH "$JAVA_HOME/bin:$PATH"

Verify:

1
2
3
echo $JAVA_HOME
java -version
javac -version

8. Troubleshooting

java: Command not found

  • Confirm OpenJDK is installed: pkg info openjdk17
  • Check what java points 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:

1
2
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/

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy