I recently found out about a game called Minecraft. It is a game that puts the player in a block-based world which can be altered by removing or placing blocks as appropriate. The player can build almost anything he or she desires. The game design is quite simplistic, but nonetheless immersive and I have to admit that I got quite addicted to it. Still, I'm more of the collaborative player, so I installed a Minecraft server instance on a remote host. The setup procedure is not very complicated if you know a bit about Linux systems. Still, I will go through each of these steps, in case a fellow reader with none or less Linux server experience wants to setup a server too. It shouldn't be hard to follow these instructions, even if you are inexperienced with Linux. The instructions apply to modified servers, like bukkit, as well.

Installing Java 6 JRE Headless

The Minecraft server software runs on the Java platform, so we need at least a runtime environment for it. You can check which Java version is currently installed on your machine by issuing the following command in a terminal.

$ java -version

If this command fails with the message "java: command not found", then you have no Java installation present on your system. You need version 1.6 and the runtime environment (JRE) suffices in order to run your Minecraft server. Get superuser access to the machine and type in the following lines.

$ apt-get install openjdk-6-jre-headless

This will initiate the download and setup process of Java 6 (JRE). After the setup has finished, type in again

$ java -version

in order to verify that the installation process completed successfully. You should see something like the following output:

>> java version "1.6.0_0"
>> OpenJDK Runtime Environment (build 1.6.0_0-b11)
>> OpenJDK 64-Bit Server VM (build 1.6.0_0-b11, mixed mode)

Obtaining the IP address of your server

Again, you need superuser access. Type the following into your terminal:

$ ifconfig

This should give you a list of all network interfaces, along with their respective IP addresses. It should look somewhat like the underneath output:

eth0      Link encap:Ethernet  HWaddr 00:13:d4:b9:33:ad
          inet addr:178.32.39.99  Bcast:0.0.0.0  Mask:255.255.255.255
          inet6 addr: fe80::213:d4ff:feb9:33ad/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:31834 errors:0 dropped:0 overruns:0 frame:0
          TX packets:29451 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:26491049 (26.4 MB)  TX bytes:3652420 (3.6 MB)
          Interrupt:21

Look for the field named "inet addr". The adress - in this case - is 178.32.39.99. This essentially means, that your server will - once we have installed it properly - be accessible to the public via this IP address. So in order to play on the server, you simply have to access it by selecting "Multiplayer" in your Minecraft client and by providing this IP address.

Creating a new user for Minecraft with restrictive rights

You should never run a server, which is open to the public, as superuser. This might compromise your entire system. In order to take countermeasures, we will create a new user which has only a few rights and cannot alter system internals. You need to be superuser for this again. Type in the following to create a user named 'minecraft':

$ adduser minecraft-user
[$ passwd minecraft-user]

Depending on your distribution, the second step might be optional. For instance, I installed a Minecraft server on Debian Lenny, and adduser took care of the password setting as well. Aside from that, you should always use strong passwords. A strong password has a minimum length of 8 characters and mixes alphanumerical literals. It might also be necessary to create a specific directory for your new user. The default location would be at /home/, in this case /home/minecraft. To set the rights for minecraft within this directory, type in the following:

$ mkdir /home/minecraft
$ chown minecraft:users /home/minecraft

Obtaining the Minecraft server and setting it up for the first time

Log into your server as 'minecraft'. I assume that your current working directory is set to '/home/minecraft'.

$ mkdir minecraft-server
$ cd minecraft-server
$ wget http://www.minecraft.net/download/minecraft_server.jar?v=1296822382921 -O minecraft-server.jar

For the first start, we will use a rather primitive starter script, which just fires up the Minecraft server. If you need a more sophisticated server management script, I suggest that you take a look at this. Before we can continue, you need to check how much free memory your Minecraft server can use. For this, type in the following command.

$ free -m

This will yield something like the following output:

             total       used       free     shared    buffers     cached
Mem:         12041      11873        167          0        464       5056
-/+ buffers/cache:       6353       5688
Swap:         4102        633       3468

The interesting number for us is 5688 (MB). It is not recommended to exhaust your free memory. But given this example output, we can easily address 2048 MB (2 GB) for our Minecraft server. Now, open up your favourite text editor and write the following lines to a file called launch_server. This file should be located at the same directory as the minecraft_server.jar!

 #!/bin/bash
 java -Xmx2048M -Xms2048M -jar minecraft_server.jar

After you saved the file, make it executable by typing:

$ chmod u+x launch_server

Execute the server by typing

$ ./launch_server

After the server started properly, you should be able to connect to it. You might have noticed that you need to be logged in at your server in order to run Minecraft. We can fix this by decoupling the Minecraft server process from your terminal session. This can be done by running the server with the following command.

$ nohup ./launch_server &

You can now log off from your server. The Minecraft server process will still be executed.

Modifying the initial server configuration

During the first successful start, the Minecraft server will generate a default configuration, which we will modify now. Your minecraft-server directory should contain a file called server.properties. If you are not familiar with the semantics of the options you have here, you should check out the Minecraft site for clarification. We will alter some basic options right now.

Your 'minecraft-server' directory should contain a file called 'server.properties' after you executed the server for the first time. If you are not familiar with the semantics of the options you have here, you should check out this link for clarification. We will just alter some basic options right now. Open up server.properties with your text editor of choice. Alter the line which begins with "server-ip" and provide your server's IP address. You could also modify the server port (the Minecraft server port defaults to 25565) if you want to. If you do so, please note that Minecraft users will not be able to connect to your server unless they specifically tell their Minecraft client to connect to this port. If you are aware of the total number of players on your Minecraft server, you should limit the max-players parameter to just that number. Also, the parameter online-mode should always be set to true, so that the Minecraft server will require authentication for Minecraft clients that want to connect to it. Please note that you need to restart your Minecraft server, otherwise changes to the server configuration won't take any effect.