Learn how you can install and configure your own Vanilla Server for Minecraft in your Ubuntu 18.04 server.


When i was just a kid, i fell in love with Minecraft because it was one of the games that used to run smooth on my old low spec computer, the dynamic of the game was incredible and all the stuff you could achieve was amazing. Till the date, the game still releases constantly updates, new items and other things. One of those amazing features was the possibility to play with friends in public servers that pitifully, aren't available anymore.

While trying to play the game with some friends again, i discovered how easy it was to host my own minecraft server in my server to play with them, so i'll explain you today how to easily setup your own self-hosted minecraft server in Ubuntu 18.04.

1. Install building requirements

Before proceeding with the configuration of your Minecraft server, you will need the following packages pre installed on your server. Before installing them, be sure to update the apt repository with the following command (initially you should have root privileges):

sudo apt-get update

Then, run the following command to install Git and the Build Essential package in your server:

sudo apt-get install git build-essential

Once you have the build essential and git in the server, you should be ready to continue.

2. Install the Headless Java Runtime Environment (JRE)

As you obviously know, Minecraft was developed in Java. In order to run the minecraft server code in your ubuntu server, you will need to have Java installed, specifically Java 8 or later. In this case, we will install the headless version of Java 8 with the following command in the server:

sudo apt-get install openjdk-8-jre-headless

We install the headless version as we won't need any graphic interface on the server 🤷‍♂️. After installing Java, you can easily check the version on the terminal with the following command:

java -version

Which should output something like:

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

With Java installed, you can continue with the next step.

3. Creating server level minecraft user

You should have an exclusive user in your ubuntu server to setup your minecraft server for security reasons, so the server won't run with root privileges. The user shouldn't have a password neither because it shouldn't be able to access your server via SSH. You can register the user with the following command:

sudo useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft

However when configuring the minecraft server you should have root privileges, so you can switch to this user later. After running the command, the new user should now exist on your system.

4. Switch to minecraft user and create directories

Now with root privileges, switch to the minecraft user with the following command:

sudo su - minecraft

In your terminal you should be logged in as the minecraft user minecraft@serverxd. Then, proceed to create the 2 directories that you will need to store the minecraft data:

  • server: this directory will contain the source of your server, the world etc.
  • tools: this directory will store the mcrcon utility that will help you to manage your minecraft server through your terminal in the server.

You can create them with the following command:

mkdir -p ~/{tools,server}

This will be created in the root directory of the minecraft user.

5. Download and compile mcrcon

Now you will need to clone the mcrcon source code in your server and compile it by yourself. mcrcon is a console based Minecraft rcon client for remote administration and server maintenance scripts. Proceed to clone the source code of the project with the following command while you're still logged as the minecraft user:

cd ~/tools && git clone https://github.com/Tiiffi/mcrcon.git

This will change the current directory to the tools directory and clone the repository using git. After cloning the repository, switch to the directory of the cloned project with the following command:

cd ~/tools/mcrcon

In this directory, run the following command to start the compilation of mcrcon using the GCC compiler:

gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c

Once the compilation finishes, you will be able to test if it works running the following command that will basically run the utility with the --help argument:

./mcrcon -h

It will output something like the following text in the terminal:

Usage: mcrcon [OPTIONS]... [COMMANDS]...
Sends rcon commands to Minecraft server.

Option:
  -h		Print usage
  -H		Server address
  -P		Port (default is 25575)
  -p		Rcon password
  -t		Interactive terminal mode
  -s		Silent mode (do not print received packets)
  -c		Disable colors
  -r		Output raw packets (debugging and custom handling)
  -v		Output version information

Server address, port and password can be set using following environment variables:
  MCRCON_HOST
  MCRCON_PORT
  MCRCON_PASS

Command-line options will override environment variables.
Rcon commands with arguments must be enclosed in quotes.

Example:
	mcrcon -H my.minecraft.server -p password "say Server is restarting!" save-all stop

mcrcon 0.6.1 (built: May 19 2019 23:39:16)
Report bugs to tiiffi_at_gmail_dot_com or https://github.com/Tiiffi/mcrcon/issues/

6. Download and configure minecraft server

After installing the control panel for the server, you will need to download the server. In this tutorial, we will use the official Vanilla server from the minecraft website of mojang. We will list here the 3 latest versions (till the date 23/04/2020, so if you are reading this article after this date, search for the latest version on the official website), however you can search on google for other versions if you need to (https://mcversions.net/):

In this case, we will use the latest 1.15.2, so we could easily download the server file with wget using the following command:

wget https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar -P ~/server

This will download the .jar file in the server directory that we created previously. Once the download finishes, you will need to temporarily start the server with the following commands:

cd ~/server && java -Xmx1024M -Xms512M -jar server.jar nogui

This will make the server start and create some basic files, however it will immediately stop throwing an exception about the necessity of accepting the EULA agreement:

[10:52:12] [main/ERROR]: Failed to load properties from file: server.properties
[10:52:12] [main/WARN]: Failed to load eula.txt
[10:52:12] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.

There will be 2 new files on the server directory namely the eula.txt and server.properties. You need to accept the EULA by simply changing the property from false to true:

#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
# Thu Apr 23 2020 10:58:54 GMT-0500 (Colombia Standard Time)
eula=true

You can do this using nano in the terminal to edit the file:

nano ~/server/eula.txt

Then, modify the server.properties file with the following command:

nano ~/server/server.properties

And change the following properties:

# 1. Configure the rcon properties
# change your-password to something secure, this will be used later
rcon.port=25575
rcon.password=your-password
enable-rcon=true
# 2. Allow online mode or not
# If you set this value to false, people with the pirate version of minecraft
# will be able to connect to your server, otherwise if it is set to true, the
# authentication of mojang will be used, so only paid versions of minecraft will work
online-mode=true

Is important to note here, that you will be the one that defines how your server will work, the previous configuration defines the correct functionality of mcrcon and if you will allow cracked minecraft versions to work with your server.

After changing the values you will be able to continue with the tutorial, do not start the server yet

7. Creating Minecraft Server as a service

Now, the recommended way to start the minecraft server is through a service, so you can easily stop, start and restart the service with the ease of a command. We will do this in Ubuntu through a systemd unit file.

Switch to the root user and create the file with the following command:

sudo nano /etc/systemd/system/minecraft.service

Set the following configuration as content of the file:

[Unit]
Description=Minecraft Server
After=network.target

[Service]
User=minecraft
Nice=1
KillMode=none
SuccessExitStatus=0 1
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/opt/minecraft/server
ExecStart=/usr/bin/java -Xmx1024M -Xms1024M -jar server.jar nogui
ExecStop=/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p your-password stop

[Install]
WantedBy=multi-user.target

The configuration file is described as next: the process will run using the minecraft user and will have as working directory the /opt/minecraft/server directory that we created initially. The ExecStart property defines the command that will run the server itself: java -Xmx1024M -Xms1024 -jar server.jar nogui. This will run the server.jar file using 1GB of max memory, you can adjust this size according to the available resources of your server and your minecraft server needs.

Save the changes in the systemd file and reload the daemon with the following command:

sudo systemctl daemon-reload

By doing this, you will be able now to start, stop and restart the minecraft server through the created service.

8. Verify that the port 25565 is open

The people should be able to connect to your minecraft server using the port 25565, so you should check that the port is open, just in case that your server is protected with a firewall, open the port with ufw:

sudo ufw allow 25565/tcp

In environments like AWS, you should open the ports in the administration interface.

9. Start minecraft server

Finally, you should be able to start the minecraft server with the following command:

sudo systemctl start minecraft

After starting it, you can see the status of the server with:

sudo systemctl status minecraft

Now your friends should be able to connect to the minecraft server using the server ip and adding as suffix your-server-ip:25565.

Happy gaming ❤️!


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors