Tuesday, January 17, 2012

Minecraft: FreeBSD

I've been running a Minecraft SMP server on FreeBSD for the better part of a year now, initially on FreeBSD 8.2 and, for the past several weeks, on a custom build of FreeBSD 9-RC3 (named 9-FUZZYKERNEL), with only two process crashes. Getting the Minecraft client to run consistently on FreeBSD can be another story, though.

Now, Java on FreeBSD is a wonky thing. It was never officially supported by Sun and/or Oracle. There are two native ports, but neither works 100% of the time, and the official Linux JDK/JRE can be run in compat mode, but it's also problematic. Now, I seem to recall that when I started playing well over a year ago, I could play on my old FreeBSD 8.x desktop, even though it was graphically unpleasant, but I could be wrong. The client now won't work with either the diablo-jdk1.6, diablo-jre1.6, or jdk1.6 Java ports. The launcher will start, but after logging in, the window shows the error "Failed to launch / Fatal error occurred (2): null" and nothing further happens. (Someone running PC-BSD 9 has the same issue, so it's not just me and not just vanilla FreeBSD.) I don't know enough about Java to know if that's a bug on the FreeBSD JDK1.6 end or on the Minecraft end, but either way, there's no game-playing joy.

Now, I don't really care, since I mostly play Minecraft on my linux craptop, but that academic curiosity kicked in. There's still the Linux JDK, which is a bigger pain in the ass to set up, but I finally got around to it, and it seems to work.1

How to Run the Minecraft Client on FreeBSD

(This should also work on PC-BSD 9, although (a) I haven't tested it, but (b) you will need to take additional steps to set up the traditional FreeBSD ports tree.)

  1. Install the following ports. (Make sure you /usr/ports tree is up to date! You've run cvsup with a good ports config, right!?2) I'm hardcore and eschew installing the pre-compiled packages in general, but since Sun's Java has specific licensing terms, you can't install it as a package anyway, so just bite the bullet, set up the ports tree, and have at it.
    • linux_base-f10
    • linux-f10-dri -- May be optional in some environments, I'm not sure, but install it if you get libGL not found errors
    • linux-sun-jdk1.6.0
  2. Make sure the linux kernel module is loaded. As root: "kldload linux"
  3. Make sure the linux proc filesystem is mounted. As root: "mount -t linprocfs linprocfs /compat/linux/proc"
  4. Since you need to set up a couple environmental variables that you won't normally want set, I suggest making a dinky startup script:
    $ cat runmc
    export JAVA_HOME=/usr/local/linux-sun-jdk1.6.0
    export LD_LIBRARY_PATH=/compat/linux/lib:/compat/linux/usr/lib:/usr/local/linux-sun-jdk1.6.0/jre/lib/i386
    java -cp minecraft.jar net.minecraft.LauncherFrame
  5. Get the Linux minecraft client jar file from minecraft.net and then have at it.
P.S. The game does seem to crash whenever I quit (at least the timing is convenient), but it freezes instead of dying. It likes to leave around a lot of java processes, too, so you may want to check and kill them as necessary.

1When I tried to run the client on my FreeBSD 9 desk top, which I had logged into over ssh with X11 forwarding on from my linux laptop, the client started, but after I logged in (the point where it starts the game launcher), I'd get the error "org.lwjgl.LWJGLException: Could not choose GLX13 config" However, if I try to play Minecraft on the FreeBSD box's local display, it works, and since I can also run Minecraft locally on the linux craptop, I assume it's some issue with X11 forwarding. Since I don't plan on playing remotely normally, it's not an issue for me.
2This is the ports-supfile I use, sans comments:
*default host=cvsup6.FreeBSD.org
*default base=/var/db
*default prefix=/usr
*default release=cvs tag=.
*default delete use-rel-suffix
*default compress


Anonymous said...

Haven't you tried the minecraft-client port (games/minecraft-client)? It does exactly what you have described.

Tell me if it's working for you!

Karen said...


I should have known they would have thought of everything already.

Anonymous said...

Have you gotten this to work with Minecraft 1.1? I am on PCBSD and cannot get it to work!

It says an error like this:

Exception in thread "Minecraft main thread" java.lang.UnsatisfiedLinkError: Can't load library: /home/oapdsf9/.minecraft/bin/natives/liblwjgl.so

Karen said...

I don't get the error about being unable to find that library. Does it exist where minecraft/java is trying to find it? I know the minecraft launcher installer is supposed to install all that stuff and its in my home directory in that path. I don't think the differences with PC-BSD and FreeBSD should affect a library that minecraft installs and uses itself.

Adam said...

I am finding FreeBSD technical musings interspersed with exotic knitting example to be somewhat disconcerting. I leave this blog more puzzled than I came.