How to install Minecraft Server on Ubuntu 20.04 LTS

Minecraft is an open world and sandbox video game developed by Mojang Studios. With Minecraft, you can build anything you can imagine with unlimited resources in Creative mode. It allows you to play online with friends as well as in single-player mode. It is one of the best video games around the world. You can create your own Minecraft server to play with your friends and play together.

In this tutorial, we will show how to set up your own Minecraft server on Ubuntu 20.04 LTS.

Prerequisites

  • A server running Ubuntu 20.04 with a minimum of 4 GB RAM.
  • A root password is set up on your server.

Getting Started

First, you will need to update your system with the latest version. You can update them with the following command:

apt-get update -y
apt-get upgrade -y

Once your system is updated, install some required dependencies with the following command:

apt-get install git build-essential -y

Once you are finished, you can proceed to the next step.

Install Java

Minecraft is written in Java language, so you will need to install the headless version of Java in your system. You can install it with the following command:

apt-get install openjdk-11-jre-headless -y

Once installed, you can verify the installed version of Java with the following command:

java -version

You should get the following output:

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Install Minecraft Server

Before starting, you will need to create a separate user for Minecraft. You can create it with the following command:

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

Next, switch the user to Minecraft with the following command:

su - minecraft

Next, create required directories for Minecraft with the following command:

mkdir ~/backups ~/tools ~/server

Install mcrcon

Next, you will need to install mcrcon in your system. mcrcon is RCON client written in C that allows you to connect to the Minecraft servers.

You can download the mcrcon to the ~/tools directory:

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

Next, change the directory to the mcrcon and build the tool with the following command:

cd ~/tools/mcrcon
gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c

Once installed, verify the mcrcon with the following command:

./mcrcon -v

You should see the following output:

mcrcon 0.7.1 (built: Jul  2 2020 07:44:45) - https://github.com/Tiiffi/mcrcon
Bug reports:
	tiiffi+mcrcon at gmail
	https://github.com/Tiiffi/mcrcon/issues/

Download and Configure Minecraft Server

First, download the latest version of Minecraft server to the ~/server directory:

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

Next, change the directory to ~/server directory and start the Minecraft server:

cd ~/server
java -Xmx1024M -Xms1024M -jar server.jar nogui

You should see the following error:

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

This is because you need to agree to the Minecraft EULA. You can do that by editing the file eula.txt:

nano ~/server/eula.txt

Change the line eula=false to eula=true as shown below:

eula=true

Save and close the file when you are finished. Next, edit the server.properties file and set the rcon password:

nano ~/server/server.properties

Change the following lines:

rcon.password=your-password
enable-rcon=true 

Save and close the file when you are finished.

Create a Systemd Unit File for Minecraft

Next, you will need to create a systemd service file to manage the Minecraft service. You can create it with the following command:

nano /etc/systemd/system/minecraft.service

Add the following lines:

[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

Save and close the file when you are finished. Then, reload the systemd daemon with the following command:

systemctl daemon-reload

Next, start the Minecraft service and enable it to start at system reboot with the following command:

systemctl start minecraft
systemctl enable minecraft

You can now verify the status of Minecraft service with the following command:

systemctl status minecraft

You should get the following output:

? minecraft.service - Minecraft Server
     Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-07-02 08:05:24 UTC; 1min 0s ago
   Main PID: 11704 (java)
      Tasks: 30 (limit: 4691)
     Memory: 1.0G
     CGroup: /system.slice/minecraft.service
             ??11704 /usr/bin/java -Xmx1024M -Xms1024M -jar server.jar nogui

Jul 02 08:06:06 ubuntu2004 java[11704]: [08:06:06] [Worker-Main-2/INFO]: Preparing spawn area: 94%
Jul 02 08:06:06 ubuntu2004 java[11704]: [08:06:06] [Server thread/INFO]: Preparing spawn area: 95%
Jul 02 08:06:07 ubuntu2004 java[11704]: [08:06:07] [Worker-Main-2/INFO]: Preparing spawn area: 96%
Jul 02 08:06:07 ubuntu2004 java[11704]: [08:06:07] [Worker-Main-2/INFO]: Preparing spawn area: 96%
Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Worker-Main-2/INFO]: Preparing spawn area: 99%
Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Server thread/INFO]: Time elapsed: 26283 ms
Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Server thread/INFO]: Done (26.613s)! For help, type "help"
Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Server thread/INFO]: Starting remote control listener
Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Server thread/INFO]: Thread RCON Listener started
Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [RCON Listener #1/INFO]: RCON running on 0.0.0.0:25575

Your Minecraft server is now started and listening on port 25575. You can verify it with the following command:

netstat -pnltu | grep 25575

You should get the following output:

tcp6       0      0 :::25575                :::*                    LISTEN      10584/java 

Access Minecraft Console

You can now access the Minecraft with mcrcon utility. You can do it by specifying the password, host and port as shown below:

/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p your-password -t

Once connected successfully, you should get the following output:

Logged in. Type 'quit' or 'exit' to quit.
>

Conclusion

In the above guide, you learned how to install Minecraft server on Ubuntu 20.04. You can now download and install Minecraft client, connect to the Minecraft server and start playing with it. Feel free to ask me if you have any questions.

Share this page:

17 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: joe

in the first couple of command i keep getting a message that says

E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

what do i need to do about this?

By: Jonathan

This whole tutorial is written under the assumption that you are logged in as root while you are executing it. Though it states that having root access is a pre-requisite, it does not state the assumption of the user being logged in as root, and does not address the fact that root access is not enabled in the default Ubuntu installation.

By: Adam

Just enter the command:

sudo -s

to become root user on Ubuntu. The follow the instructions of the tutorial.

By: Xadeone

Might sound like a completly dumb question but when executing the first step at "Create a systemd unit file for minecraft" it says that I don't have permission. Tried logging as root and of course it asked me for a password, but I didn't set any and I don't know what it is.

By: till

@Xadeone: Run the command:

 

sudo -s

 

to become root user. The password that it asks for is the password of your normal Linux user, the one that you use for administrative tasks via sudo.

By: vuk

how do i find the save files? i've been looking into all of the directories that i could think of, but i am guessing i've forgotten something. The reason i need the saves is because i'm trying to update the server to 1.16.4 but i want to keep the world that we've played on so far.

By: Abdul-Hakeem

The "sudo - minecraft" part doesn't seem to work. I have a root password configured, but it doesn't accept it. But if I just do "su" by itself, the password works.

What is the command supposed to do? Are you switching to root user, or to minecraft user? Or giving root privs to the minecraft user?

By: Frank

Hello,

 

using 

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

i get 

In file included from /usr/include/string.h:495,

                 from mcrcon.c:28:

In function ‘strncpy’,

    inlined from ‘packet_build’ at mcrcon.c:576:2:

/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound 4096 equals destination size [-Wstringop-truncation]

  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));

      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

which looks like a failed work.

 

Do you have an idea what is missing?

 

Thanks in advance

Frank

By: Das

same

By: Gary Attaway

Thanks for the great tutorial. I had to make one modification to the Systemd Unit File:

ExecStop=/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -p your-password stop

Including the port number caused an error and the minecraft server did not shutdown.

By: iv

i did all the above and everything went as planned but when trying to join the server it sais: Failed to connect to the server

io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused:

By: circusafro

The other things I've done with this: 

Create a script that will open the console for you: echo '/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p [your-password] -t' > /opt/minecraft/console.shchmod +x /opt/minecraft/console.shUpdate the version of minecraft to the latest paper version (low resource utilisation):cd /opt/minecraft/serverwget https://papermc.io/api/v2/projects/paper/versions/1.16.5/builds/445/downloads/paper-1.16.5-445.jarmv server.jar original.jarln -s ./paper-1.16.5-445.jar ./server.jarsystemctl stop minecraftsystemctl start minecraftReconfigure the server to prefer IPV4 by adding "-Djava.net.preferIPv4Stack=true" to the service file aboveExecStart=/usr/bin/java -Xmx1024M -Xms1024M -Djava.net.preferIPv4Stack=true -jar server.jar nogui

Add the first admin user

./console.sh/op [user_name]This will automatically add the user to the ops.json file

By: Xadeone

I can't access de console. I've checked my password and ip, but it keeps throwing at me "Connection failed.Error 111: Connection refused" and I'm not sure what might be causing it.

By: stun

How do you upgrade server from 1.16 to 1.8?

By: Fred

Great tutorial!

Tank you!

By: Patrick

 

How do I solve this error?

LinkageError occurred while loading main class net.minecraft.server.Main    java.lang.UnsupportedClassVersionError: net/minecraft/server/Main has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java Runtime only recognizes class file versions up to 55.0

I'm running the lastest version:

java -versionopenjdk version "11.0.11" 2021-04-20OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

By: theo

I set up the server but i can not access it. the server seems to be running. idk what im missing. the server is hosted offsite