Install Minecraft server on ubuntu server 22.04
Back to Home / Back to Notes

Install Minecraft server on ubuntu server 22.04

Summary:

1 - Prepare the server

2 - Install the Minecraft server

3 - Run the Minecraft server

4 - Prepare external backup storage

Tutorials used as reference: KeepItTechy on Youtube / DigitalOcean tutorial

1 - Prepare the server

Install the OS

1 - Prepare a USB drive with an ISO of Ubuntu server 22.04 LTS

2 - Plug the USB Drive on the server

3 - Turn on the machine

4 - Press F12 or DEL to access boot menu

5 - Select the USB drive on UEFI mode

6 - Boot the Dell Optiplex 7050 and install the OS.

Use the following settings:

Now that I know the IP, I can SSH into it and edit the SSH default port.

Connect to the server

So, first, the SSH connection (usernames and IPs are fake):

ssh username@192.168.1.20

We are in!

Update the Server:

Once I logged in with SSH into the server, we download the latest updates to ensure security

sudo apt update
sudo apt upgrade -y

2 - Install the Minecraft server

Java Installation:

------Note------

Depending on the server version, a different Java version might be needed:

Minecraft 1.20.5 and newer (Java 21)

Minecraft 1.17 until 1.20.4 (Java 17)

Minecraft 1.16 and older (Java 8)

------Note------

For Minecraft, we need Java, if it is Windows or Linux. So we download and isntall the latest version needed.

sudo apt install openjdk-18-jdk -y

Check Java version:

Now we make sure it is correctly isntalled with no errors:

sudo java -version

Create Minecraft user for the server:

We log in by SSH with our username but we want to create a separate one specifically to run the server so we can use the main one for other tasks.

sudo adduser minecraft

Add the user to the sudo group:

sudo usermod -aG sudo minecraft

change account:

su - minecraft

Create a folder for the server:

mkdir minecraft ls (to make sure it's there)
cd minecraft/ (to go into this folder)

Open Minecraft Server website:

https://www.minecraft.net/en-us/download/server
Right clic on the link that downloads the file and select "Copy URL address"

Download the Jar file

wget -O server.jar https://launcher.mojang.com/v1/objects/123456.....789654/server.jar

"server.jar" will be the name of our downloaded file, but the name can be changed to make it easier to identify the version we are downloading:

wget -O whateveryouwant.jar https://launcher.mojang.com/v1/objects/123456.....789654/server.jar

wget -help says:

-O, --output-document=FILE write documents to FILE

Older versions of Minecraft server can be found here

Now we have the "server.jar" downloaded, we can do ls to check it is correctly there.

Change the filename (optional):

mv server.jar minecraft-server-1.19.2.jar

ls (to check it is here)

Make the file executable

sudo chmod +x minecraft_server_1.19.jar

ls to check it is changed color (meaning it is executable now)

3 - Run the Minecraft server

Screen to run server in background:

We want to run the server on the background and leave the terminal. But if we just launch the server and quit, it will kill the server too.

Therefore, we do:

screen

press Enter

cd minecraft/

This will open a new session with the same user in which we can run the server and leave it properly. After, we go to the directory we created, where our files are stored.

Load the server:

java -Xms1024M -Xmx4096M -jar minecraft-server-1.19.2.jar nogui

Accept EULA

sudo nano eula.txt

We have to change "eula=false" to "eula=true"

Leave the server running:

In order to exit screen without stopping anything, we press: "CTRL" + "A" + "D"

Verify server still running:

To confirm that it is still running in the background, we can check the screen service running and his ID:

screen -list

This will appear:

minecraft@sb20srv2:~$ screen -list
There is a screen on:
14689.pts-1.sb20srv2 (08/18/2022 08:25:25 AM) (Detached)
1 Socket in /run/screen/S-minecraft.

We can also check with HTOP to view Processus running:

htop

Processes should show "minecraft" (our user) running on top of CPU or Ram usage). to get back to this session and stop the server for exemple, we do:

screen -r 14689

We stop the Minecraft server:

stop

We exit the screen session:

exit

We verify screen is not running:

minecraft@sb20srv2:~$ screen -list
No Sockets found in /run/screen/S-minecraft.

Now, We can turn on the computer, turn on the server, let it run in the background, still manage the server without interrupting the Minecraft server or just quit the server.

So now, we need to do backups of this server for security. Before that, I used FreeFileSync on Windows to manually backup the data on an external USB Drive. Now we will see how to do it using BorgBackup.

Tutorial - How to backup on an external disk using BorgBackup