How to Install Java on FreeBSD

The write once, run anywhere language is needed for a whole bunch of applications. Installing Java on FreeBSD is very straightforward. You can either choose to install the Open JDK or the Oracle JDK Java Development Kit. The OpenJDK Java Development Kit is the native port of OpenJDK to FreeBSD. The Oracle JDK Java Development Kit is a patchset of the JDK source code released by Oracle. This port builds a native JDK for FreeBSD.

Root access is required to edit the following files and to execute commands. Log in as root (su) or simply prepend sudo to all commands that require root privileges.

Installing OpenJDK on FreeBSD

Navigate to the port directory and install Java with the following commands:

cd /usr/ports/java/openjdk6
make install clean; rehash

Installing Oracle JDK on FreeBSD

Navigate to the port directory and install Java with the following commands:

cd /usr/ports/java/jdk16
make install clean; rehash

Please note that with the Oracle JDK Java Development Kit you have to manually fetch the source code and patchset for FreeBSD.

Configure Java on FreeBSD

Once the SDK is installed, it is useful to add its location to the environment. Place the following lines in /etc/profile: