Minecraft Server on Ubuntu

I’m not a gamer, but I have an offspring who is deeply obsessed with Minecraft. I set up a Minecraft server for her so that she can play with her friends online in a safe environment.

⚠️ I’m focusing on the Java edition of Minecraft. If you’re a Bedrock user and would like to collaborate with me on a server setup, please get in touch!

Hardware Requirements

You can run the server on a local machine (laptop or desktop) or a cloud server. I’ll consider both options here. If you’re going the (headless) cloud server route then I’d suggest something at least like a t3.small EC2 instance, which should have enough beef to handle a few concurrent clients.

If you are going to run the Minecraft server on a machine with limited RAM then you might want to add swap space.

Install JRE

Since the Minescraft server is a Java application you’ll need to install a Java Runtime Environment (JRE). First update the APT package source list.

sudo apt update

Then install the JRE package. Choose whichever option is appropriate to your server.

# Desktop Server
sudo apt install -y openjdk-18-jre
# Headless (Cloud) Server
sudo apt install -y openjdk-18-jre-headless

Enable Access

You’ll need to ensure that the Minecraft clients are able to access the server. On the Desktop Server you’ll add a firewall rule.

sudo ufw allow 25565

On the Headless Server ensure that there is a suitable rule in place to allow inbound connections on port 25565.

Minecraft Server Download

Go to the Minecraft server download page and download the server package. On the Desktop Server you can simply trigger the download via your browser. On the Headless Server you’ll need to use a CLI tool like wget. Get the URL for the most recent server release from the link above.

wget https://piston-data.mojang.com/v1/objects/8dd1a28015f51b1803213892b50b7b4fc76e594d/server.jar

Accept the EULA

Create a file called eula.txt with the following content:

eula=true

Run Server

Now launch the server. You can take the headless approach on both Desktop or Headless machines, but on Desktop machine you might also want to be able to see Minecraft server UI. There’s not too much to be gained by that though because it’s not very informative.

# Desktop Server
java -Xms1024M -Xmx1024M -jar server.jar
# Headless Server
java -Xms1024M -Xmx1024M -jar server.jar nogui

While the server is launching there will be copious logs on the terminal. It will look something like this (aggressively redacted):

[Server thread/INFO]: Starting minecraft server version 1.20.4
[Server thread/INFO]: Loading properties
[Server thread/INFO]: Default game type: SURVIVAL
[Server thread/INFO]: Generating keypair
[Server thread/INFO]: Starting Minecraft server on *:25565
[Server thread/INFO]: Using epoll channel type
[Server thread/INFO]: Preparing level "world"
[Server thread/INFO]: Preparing start region for dimension minecraft:overworld
[Server thread/INFO]: Time elapsed: 8589 ms
[Server thread/INFO]: Done (17.062s)! For help, type "help"

Server IP

You’re going to need to have the server’s IP address in order to connect from the Minecraft client. Either get this from the EC2 console for Headless or via the terminal for Desktop:

hostname -I

Server Configuration

You can tweak a variety of server configuration options via the server.properties file

Security & Limiting Access

You can make your Minecraft server more secure by moving it to a non-standard port. Edit the configuration file and choose an alternative port:

server-port=30100

You’ll need to ensure that inbound access is allowed on this port (as we did above for the default port).

This is not a particulary robust solution to securing the server but it will reduce the likelihood of your server being discovered by somebody looking for machines accepting connections on the default Minecraft port.

Game Mode

You can choose the default game mode by editing the gamemode property.

gamemode=survival

Valid options are:

  • survival
  • creative
  • adventure and
  • spectator.

Operator Permission Level

An operator is a player with elevated privileges. It’s something like an admin user. There are four operator levels:

  1. Basic — Bypass spawn protection.
  2. Single player — Use /clear, /difficulty, /effect, /gamemode, /gamerule, /give, /summon, /setblock and /tp and can edit command blocks.
  3. Multi-player — Use /ban, /deop, /whitelist, /kick and /op.
  4. Server — Use /stop, /save and /save-all.

The op-permission-level property determines which of these levels applies to operators.

op-permission-level=2

Other Properties

You might find it useful to update the values for these properties too:

  • difficulty
  • level-seed
  • max-players
  • motd
  • online-mode (useful for offline or LAN-only servers) and
  • white-list (a list of players who can connect to the server).

Server Console

You can interact with the running server via the console.

Giving commands directly to the server is somewhat different from giving commands in the client since you’re not actually playing the game. Some commands will require you to specify a username. For example, to change the game mode for a specific player:

/gamemode creative datawookie

Of course it’d be easier if the players themselves could make the change. In order for that to be possible you need to enable cheats, which is done by making a player into an operator. See notes on operator permission level.

/op datawookie

You can then disable cheats again later.

/deop datawookie

Server Persistence

If you want the server to continue running after you have disconnected the terminal then you’ll either want to launch it in the background using nohup or run it in a tmux or screen session.

FAQ

Q. How do I reset the map?
A. Stop the server. Either (1) delete the world/ directory or (2) edit server.properties and provide a new value for level-name. Then restart the server.

Enjoy

Once the server is up and running you can connect to it from a Minecraft client.