How to Install Minecraft Server on Ubuntu 18.04 LTS
This tutorial exists for these OS versions
- Ubuntu 20.04 (Focal Fossa)
- Ubuntu 18.04 (Bionic Beaver)
On this page
Minecraft is one of the most popular games in the world developed by Microsoft Studious. Minecraft is a sandbox video game and allows you to build anything you need and explore it in a 3D world. With Minecraft, you can play the game online with your friends as well as in single-player mode. Minecraft is available on a wide range of platforms including, Linux, macOS, and Windows.
In this tutorial, we will learn how to install a Minecraft server on Ubuntu 18.04 server.
Requirements
- A server running Ubuntu 18.04.
- A root password is setup to your server.
Getting Started
Before starting, you will need to update your system with the latest version. You can do this by running the following command:
apt-get update -y
apt-get upgrade -y
Once your server is updated, restart your server to apply the changes.
Next, you will need to install some dependencies on your server. You can install all of them with the following command:
apt-get install git build-essential -y
Install Java
Since Minecraft is developed with Java program language. So you will need to install Java development Kit or JRE on your server. You can install Java with the following command:
apt-get install openjdk-8-jre-headless -y
Once installed, verify the Java with the following command:
java -version
You should get the following output:
openjdk version "1.8.0_222" OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10) OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
Install and Configure Minecraft Server
First, you will need to create an user to run Minecraft server. You can create it with the following command:
useradd -r -m -U -d /home/minecraft -s /bin/bash minecraft
Next, login to minecraft user with the following command:
su - minecraft
Next, create a required directory for minecraft with the following command:
mkdir backups tools server
Next, change the directory to the ~/tools directory and download mcrcon from the Git repository:
cd ~/tools
git clone https://github.com/Tiiffi/mcrcon.git
Next, change the directory to mcrcon and compile the mcrcon with the following command:
cd mcrcon
gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c
You should see the following output:
mcrcon.c: In function ‘get_line’: mcrcon.c:752:2: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result] (void) fgets(buffer, bsize, stdin); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Next, change the directory to ~/server and download the latest Mojang's official vanilla Minecraft server with the following command:
cd ~/server
wget https://launcher.mojang.com/v1/objects/3dc3d84a581f14691199cf6831b71ed1296a9fdf/server.jar
Once the download is completed, start the Minecraft server with the following command:
java -Xmx1024M -Xms512M -jar server.jar nogui
You should get the following error:
[06:00:45] [main/ERROR]: Failed to load properties from file: server.properties [06:00:48] [main/WARN]: Failed to load eula.txt [06:00:48] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
To resolve this error, you need to agree to the Minecraft EULA in order to run the server.
To do so, open eula.txt file:
nano eula.txt
Change eula=false to eula=true as shown below:
eula=true
Save and close the file. Then, open the server.properties file to enable the rcon protocol and set the rcon password.
nano server.properties
Change the following lines:
rcon.port=25575 rcon.password=admin@123 enable-rcon=true
Save and close the file when you are finished. Then, exit from the Minecraft user with the following command:
exit
Create a Systemd Service 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=/home/minecraft/server ExecStart=/usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui ExecStop=/home/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p admin@123 stop [Install] WantedBy=multi-user.target
Save and close the file. Then, reload the systemd daemon with the following command:
systemctl daemon-reload
Next, start the Minecraft service and enable it to start after system reboot with the following command:
systemctl start minecraft
systemctl enable minecraft
You can also check 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 Mon 2019-10-07 06:33:32 UTC; 6s ago Main PID: 4318 (java) Tasks: 34 (limit: 4915) CGroup: /system.slice/minecraft.service ??4318 /usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Loading properties Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Default game type: SURVIVAL Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Generating keypair Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Starting Minecraft server on *:25565 Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Using epoll channel type Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Preparing level "world" Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Found new data pack vanilla, loading it automatically Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Reloading ResourceManager: Default Oct 07 06:33:38 ubuntu1804 java[4318]: [06:33:38] [Server thread/INFO]: Loaded 6 recipes Oct 07 06:33:38 ubuntu1804 java[4318]: [06:33:38] [Server thread/INFO]: Loaded 811 advancements
Test Minecraft
Minecraft server is now installed and running. It's time to test it.
Open your terminal and access the Minecraft Console with mcrcon utility as shown below:
/home/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p admin@123 -t
Once connected, you should get the following output:
Logged in. Type "Q" to quit! >
Congratulations! you have successfully installed and configured Minecraft server on Ubuntu 18.04 server. Feel free to ask me if you have any questions.