User Tools

Site Tools


games:minecraft:create_a_minecraft_server

Games - Minecraft - Create a Minecraft Server

NOTE: These instructions are for installing a basic vanilla Minecraft server without any add-ons or plugins.


Install Ubuntu Server

Install the Ubuntu OS as usual.


Update the packages

apt update
apt upgrade

Install Apps

apt install tmux wget git most htop

Install Java

apt install openjdk-16-jdk

Create a User Account

adduser minecraft --disabled-login --disabled-password

NOTE: It is best to have a separate user account to avoid possible security vulnerabilities on the system.

  • Simply press the Enter key to skip filling in the usual account information.
  • No password is specified for this user.
    • The account is only going to be accessible from the root account.

Switch to the new user

su - minecraft

Create a directory to hold the Minecraft server

mkdir ~/server && cd ~/server

Install the Minecraft server

Visit the official Minecraft site, https://minecraft.net/download/server, and right-click on the Download link and copy the Link Location from the context menu.


Download the Minecraft Java file

wget download_link

NOTE: download_link is the link from the previous step.


Agree to the End User License Agreement

echo "eula=true" > eula.txt

NOTE: This creates a file named eula.txt.

  • This tells the software that the Minecraft End User License Agreement is accepted.
  • The terms and conditions can be viewed on the Minecraft website.

Start the Minecraft Server

tmux -s new minecraft
java -jar server.jar

NOTE: Tmux is being used to allow detaching of the session.

  • Enter help for a list of commands.
  • To shut down your server, enter the command stop.

NOTE: Some people suggest the server runs quicker using

java -jar server.jar --nogui
  • But this prevents a GUI for typing commands, so only use this option is that is not a concern.

Enhance the Minecraft Server

For add-ons, mods and to personalize the Minecraft experience consult this official documentation: https://help.mojang.com/.


Connect to the Minecraft Server

Download the Minecraft client from the official Minecraft website.

Install and launch the client and sign in.


Create a Server startup script

Create /etc/systemd/system/minecraft.service.

/etc/systemd/system/minecraft.service
[Unit]
Description=Minecraft server
Documentation=
Wants=network.target
After=network.target
 
[Service]
WorkingDirectory=/home/minecraft/server
User=minecraft
Group=minecraft
Type=forking
# Run it as a non-root user in a specific directory
 
ExecStart=/usr/bin/tmux -s new minecraft "java -jar server.jar"
 
# Send "stop" to the Minecraft server console
ExecStop=/usr/bin/tmux kill-session -t minecraft
# Wait for the PID to die - otherwise it is killed after this command finishes!
ExecStop=/bin/bash -c "while ps -p $MAINPID > /dev/null; do /bin/sleep 1; done"
# Note that absolute paths for all executables are required!
 
[Install]
WantedBy=multi-user.target

Run the Startup Script

systemctl daemon-reload
systemctl start minecraft

References

games/minecraft/create_a_minecraft_server.txt · Last modified: 2021/07/08 19:48 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki