June 18, 2024

How to Host Your Own Minecraft Server

Minecraft is a very popular game and a big part of its appeal is the ability to run your own servers. It’s surprisingly simple to host a Minecraft server, and you can get one up and running quickly. Here we show you how you can host a Minecraft server, both as a system service and a Docker container.

Why Host Your Own Minecraft Server?

One of the biggest reasons why you should host your own Minecraft server is that it gives you privacy over your Minecraft world. Hosted services, such as Minecraft Realms, are subject to Mojang’s strict policies, which can lead to unfair and unwarranted global bans for your players.

Aside from that, hosting your own Minecraft server also gives you complete control over your world’s dimension files. This allows you to back up your world and perform server-wide edits through WorldEdit and Litematica.

A screenshot of a Minecraft client running Litematica.

Lastly, self-hosting a Minecraft world enables you to introduce gameplay changes through various mods and mod packs. For example, installing Minecraft Spigot Server on a hosted service is impossible if either your provider’s web panel or hosting plan doesn’t cover it.

On a side note: explore some of the best sandbox games that aren’t Minecraft.

Preparing the System for the Minecraft Server

Assumption: The instruction listed here is done on an Ubuntu machine with 4GB of RAM from DigitalOcean. It also assumes that you currently own a domain name which you can add DNS records to.

You’re going to need a few software packages before you can run the Minecraft server. You can install them directly with Ubuntu’s apt package manager. Begin by running the following command in the terminal on your server:

sudo apt install default-jdk tmux wget
A terminal showing the dependencies for the Minecraft server.

Go to your domain registrar’s DNS records page, then create a new “A” record pointing to your Minecraft server’s IPv4 address:

A screenshot showing the DNS record for the Minecraft server.

Create the directory where you want to run the server and go inside it. You can do everything out of your home directory, if that’s most convenient for you:

mkdir ~/minecraft && cd ~/minecraft

Open a web browser on your host machine, then navigate to Minecraft’s server download page.

Locate the download link for the server’s .jar file, then copy that link to your system’s clipboard.

A screenshot showing the location of the download link for the Minecraft server.

Go back to your server’s terminal window, write the following command, then paste the link on your clipboard:

wget -O minecraft_server.jar PASTE-YOUR-LINK-HERE
A terminal showing the process of downloading the server .jar file using wget.

In order to run the latest Minecraft server, you need to accept the game’s EULA. You do that by creating a “eula.txt” file in the same directory as your server. The server will read the file and see that you’ve accepted the license:

echo "eula=true" > eula.txt

Installing and Running the Server

You don’t need a startup script, but it’s easier to just combine things into a script so you only need to run one command to start up your server. Begin making a new file by opening it with your text editor:

Paste the following block of code inside your new script file:

#!/bin/bash
 
tmux new-session -s $1 '/usr/bin/java -Xmx4096M -Xms4096M -jar minecraft_server.jar nogui'

Note: You can automatically run this script on the background by adding a -d flag after the new-session subcommand.

Save your script and exit the text editor. You’ll also need to make your script executable before you can run it:

chmod u+x ./start-server.sh

You’re finally ready to start up your server. Give it a name that you can easily identify in quotes when you run the script:

./start-server.sh "my-server"

Your server will start up and generate your world’s terrain and biomes. Wait until it prints “Done!” on the server prompt.

A terminal showing the "Done" output from the Minecraft server's prompt.

Open your Minecraft client, go to the Multiplayer screen, then click “Add Server.”

Provide a name for your new record, then type the complete address of your server.

A screenshot showing the server details prompt in the Minecraft client.

Test your connection to your new Minecraft server by double-clicking the server’s entry on the Multiplayer screen.

A screenshot showing the list of available servers in the Minecraft client.

Tip: learn how you can speed up your Minecraft client using OptiFine.

Updating the Default Server Configuration

While the default server config will work for most users, it’s possible to modify how your server behaves by editing its “server.properties” file. This contains the core options for your server, such as its difficulty mode, render distance, and level seed.

Start by running the stop command on your server’s console to gracefully save and shut down your Minecraft world.

A terminal showing the

Make sure that you’re in your server’s directory, then create a backup of your original “server.properties” file:

cd ~/minecraft-server && cp ./server.properties ./server.properties.backup

Open the original server.properties file using your favorite text editor:

Inside, you can modify every default variable of your server to your liking. For instance, changing the pvp variable to “false” will disable any player combat for the server.

A terminal highlighting the

Save the modifications that you’ve made on your server.properties file, then run ./start-server.sh my-server to reload your server with your new config.

Running a Minecraft Server in Docker

Aside from being a system service, you can also run your Minecraft server as a Docker container. This allows you to easily deploy and move your server from one machine to another as well as modify and rebuild your server to any Minecraft version that you want.

Start by installing Docker on your Linux machine, then run docker -v to confirm that the daemon is working properly.

A terminal showing the Docker daemon working properly on the machine.

Make a new folder in your home directory, then go inside it:

mkdir -p ~/minecraft-docker/data && cd ~/minecraft-docker

Create a “docker-compose.yml” file inside your Minecraft Docker directory using your favorite text editor:

nano ./docker-compose.yml

Paste the following block of code inside your Docker Compose file:

services:
  mc:
    image: itzg/minecraft-server
    tty: true
    stdin_open: true
    ports:
      - "25565:25565"
    environment:
      EULA: "TRUE"
      VERSION: "1.20.6"
    volumes:
      - ./data:/data

Save your Compose file, then run the following command to start the build process:

sudo docker compose up -d

Check that the Minecraft server is running by listing the active containers in the system:

A terminal showing the Minecraft container running properly on the server.

Connect to your new Minecraft world by going to your client’s Multiplayer menu, then providing your server’s address under “Direct Connection.”

A screenshot showing the Minecraft world running inside the Docker container.

Rebuilding the Minecraft Server Container

One of the advantages of using Docker is that it’s very easy to change the core parts of your Minecraft server, such as its version, mod framework, and networking stack. This can be especially useful you want to try out different server configs without investing on a full server controller like Crafty.

Start by shutting down your Docker Compose deployment:

Open your “docker-compose.yml” file using your favorite text editor:

nano ~/minecraft-docker/docker-compose.yml

Scroll down to the “env:” section, add the “TYPE” variable under “VERSION,” then set its value to “paper.”

A terminal highlighting the

Save your new .yml file, then run sudo docker compose up -d to rebuild your new Minecraft server with the Paper backend.

A screenshot showing the

Learning how to host your own Minecraft server is just one of the few things that you can do with this wonderful sandbox game. Explore the different worlds that you can generate by looking at some of the best Minecraft seeds available today.

Image credit: ELLA DON via Unsplash. All alterations and screenshots by Ramces Red.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.

Leave a Reply

Your email address will not be published. Required fields are marked *