Minecraft Server Prerequisites
To have Minecraft on your Linux PC, you need:
- Minimum 5GB RAM
- Dedicated game server
- Intel core-based CPUs
- Access to the Command Line
Install the packages to create the mcrcon tool:
$ sudo apt update
$ sudo apt install git build-essential
Steps of Installing Minecraft Server on Linux Ubuntu
Follow the steps given below to have a smooth Minecraft install on your Linux PC.
Install JRE
The latest versions of Minecraft require Java 17+ to run.
For Minecraft, one needs to use headless JRE, because Minecraft isn’t compatible with a graphical user interface.
So, OpenJRE 17 package will be installed by:
$ sudo apt install openjdk-17-jre-headless
And verify the installation through:
$ java -version
Install Minecraft on Linux Ubuntu
Create three new directories by writing the code below:
$ mkdir Minecraft-Server
Navigate to this folder now – by typing
$ cd Minecraft-Server
Then – create (3) new subfolders, in that folder.
$ mkdir {backups,tools,server}
So what’re these directories for?
- The backups will take a server backup.
- The tools will keep the backup script and the mcrcon client.
- The server directory stores the Minecraft server and the related details.
Download and Compile mcrcon
RCON protocol lets you execute commands when you’re connected to your Minecraft server on Linux Ubuntu.
And mcrcon is a C-based RCON client.
From GitHub, download the source code and create the mcrcon binary.
To do this, navigate to the tools and clone Tiiffi/mcrcon using this command:
$ cd tools && git clone https://github.com/Tiiffi/mcrcon.git
After that, switch back to your repository directory:
$ cd mcrcon
Compile the mcrcon utility via:
$ gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c
And then test it by:
$ ./mcrcon -h
Download the Minecraft Server on Linux Ubuntu
Minecraft server mods like Spigot or Craftbukkit let you add plugins on your Minecraft server. You can also customize the server settings.
Here we’re installing Mojang’s vanilla Minecraft server.
You can download the Java archive file (JAR) of the Minecraft server from this page manually – or do via WGET command. To get latest download link – visit the link above and do Copy Link on the minecraft_server.jar URL.
Navigate to your server folder:
cd ~/Minecraft-Server/server
Then download the server.jar:
$ wget https://piston-data.mojang.com/v1/objects/84194a2f286ef7c14ed7ce0090dba59902951553/server.jar -P
Configure Minecraft Server
Remain in /server folder from above step. Type the following command to startup the server for the first time.
$ java -Xmx1024M -Xms512M -jar server.jar nogui
Minecraft server will perform some operations and will create server.properties and eula.txt.
Agree to the EULA to run the server. For this, open the eula.txt and change eula=false to eula=true:
$ nano ~/Minecraft-Server/server/eula.txt
Then close that file and save by typing CTRL+O and pressing Enter
Now, edit the server.properties to enable rcon and set a suitable rcon password.
Open your text editor by typing:
$ nano ~/Minecraft-Server/server/server.properties
Update the values in the following manner – if something is in italics you will create / type your own option.
rcon.port=25575
rcon.password=strong-password
enable-rcon=true
Not Required – but you can also modify your server settings, the following is what I change:
motd=Change this to whatever you want your Message of the Day to Be.
difficulty=hard
Build Systemd Unit File
Minecraft can be run as a service only after creating a Systemd unit file.
Create a file called minecraft.service in /etc/systemd/system/ :
$ sudo nano /etc/systemd/system/minecraft.service
Paste the configuration as follows – please note – anything in italics will need to be modified to your user or directory. If you follow my guide and your username is mcadmin – you can copy paste as normal.
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=mcadmin
Nice=1
KillMode=none
SuccessExitStatus=0 1
ProtectHome=false
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/home/mcadmin/Minecraft-Server/server
ExecStart=/usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui
ExecStop=/home/mcadmin/Minecraft-Server/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password stop
[Install]
WantedBy=multi-user.target
Modify Xms and Xmx flags as per your server resources.
The Xms flag defines the initial memory allocation, while the Xmx defines the maximum memory allocation for a JVM (Java Virtual Machine)
You need to use the correct rcon password and port. Always keep this in mind.
Execute the command below to begin with the Minecraft server.
$ sudo systemctl start minecraft
Check the Minecraft service status with:
$ sudo systemctl status minecraft
Finally, the command below will enable the Minecraft service at boot time:
$ sudo systemctl enable minecraft
Adjust the Firewall
Open port 25565 to access the Minecraft server from other than your local network while the server has a firewall.
Allow traffic on the port 25565 by:
$ sudo ufw allow 25565/tcp
Configure Backups
We’ll create an automatic backup using shell script and cronjob.
Create the following file in your text editor:
$ nano ~/Minecraft-Server/tools/backup.sh
Then paste the configuration given below (replace the paths in MCRON_PATH, BACKUP_PATH, and MC_PATH with your specific paths)
#!/bin/bash
MCRCON_PATH="/usr/local/bin"
BACKUP_PATH="/home/opc/mc_backup"
MC_PATH="/home/opc/minecraft"
IP="127.0.0.1"
PORT="25575"
PASS="[password]"
function rcon {
$MCRCON_PATH/mcrcon -H $IP -P $PORT -p $PASS "$1"
}
rcon "save-off"
rcon "save-all"
tar -cvpzf $BACKUP_PATH/server-$(date +%F_%R).tar.gz $MC_PATH
rcon "save-on"
## Delete older backups
find $BACKUP_PATH -type f -mtime +7 -name '*.gz' -delete
Run the following command to save the file and make your script executable.
$ chmod +x ~/Minecraft-Server/tools/backup.sh
Then, create a cron job by typing:
$ crontab -e
0 23 * * * ~/Minecraft-Server/tools/backup.sh
The second line will make the backup script run every day at 23:00.
Access Minecraft Console
Use the mcrcon utility to get hold of the console of Minecraft.
The syntax is given below:
$ /opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password -t
The rcon port mustn’t be blocked while accessing the Console.
The Conclusion
And that’s the end of this tutorial. You’ve installed the Minecraft server on Linux Ubuntu successfully. Set up a backup on a regular basis.
Leave a Reply