The beauty of having your own Minecraft server is that you're totally in charge of your gaming experience. You get to choose what settings are used on the server, you can use (or abuse) your admin powers for an advantage, and bestow those powers on to your fellow gaming buddies. You may want to create a private server for just you and your friends, or make it public for everyone to access.
Ubuntu 20.04 Focal Fossa is a top choice for hosting a Minecraft server, as Linux is known for its stability when running servers and Ubuntu is known for its ease of use. Follow along below as we take you through the steps to get your Minecraft server up and running.
In case you're also wondering how to play Minecraft on Ubuntu 20.04, we've got you covered for that too. Just check out our other guide about how to install Minecraft on Ubuntu 20.04 Focal Fossa Linux.In this tutorial you will learn:
- How to install and configure Minecraft Server
- Create Minecraft SystemD startup script
- Provision new Minecraft server instance on the same host
|Category||Requirements, Conventions or Software Version Used|
|System||Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa|
|Software||Minecraft, plus Java and various prerequisites|
|Other||Privileged access to your Linux system as root or via the
# - requires given linux commands to be executed with root privileges either directly as a root user or by use of
There are a few packages we'll need in order to run the Minecraft server, so let's start by installing them. Open a terminal and type the following two commands:
$ sudo apt update $ sudo apt install wget screen default-jdk nmap
wgetwill be used to download Minecraft server fies
screenis for running the Minecraft server in the background
default-jdkis a Java package that Minecraft needs in order to run
nmapwill be used later on for basic troubleshooting purposes
Create a Minecraft user
It's best practice to let the Minecraft server run under its own dedicated account, rather than using root or some other account. Create a new account in Ubuntu with the following command:
$ sudo useradd -m -r -d /opt/minecraft minecraft
Install Minecraft server
- It's possible to run multiple instances of the Minecraft server on a single host. We'll show you how to do this later in the article, in case you're wanting to run multiple servers. Each server instance we run will need its own directory under the
/opt/minecraftdirectory. For this first server instance, let's call it
survivaland create the following directory:
$ sudo mkdir /opt/minecraft/survival
- Now, we need to download the Minecraft server Java file with
wget. Since Minecraft receives regular updates, you'll need to make sure you're downloading the latest version by going to the official Minecraft download page and copying the link to the .jar file.
- Use the following command to download the file, replacing the link in this example with the current one available:
$ sudo wget -O /opt/minecraft/survival/minecraft_server.jar https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar
- You need to accept the terms and conditions before being able to install the Minecraft server. Use this command:
$ sudo bash -c "echo eula=true > /opt/minecraft/survival/eula.txt"
- Lastly, we need to give our
minecraftuser account ownership on the Minecraft server directory:
$ sudo chown -R minecraft /opt/minecraft/survival/
Create Minecraft SystemD startup script
Adding a Minecraft startup script to SystemD will make it really convenient to start your Minecraft server any time you need to put it up, such as after a system reboot. It also gives you an easy way stop the restart the server.
- Start by creating the following file with nano or your preferred text editor:
$ sudo vi /etc/systemd/system/minecraft@.service
- Paste the following content in the new file:
[Unit] Description=Minecraft Server: %i After=network.target [Service] WorkingDirectory=/opt/minecraft/%i User=minecraft Group=minecraft Restart=always ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN IN 5 SECONDS. SAVING ALL MAPS..."5' ExecStop=/bin/sleep 5 ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"5' ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"5' [Install] WantedBy=multi-user.target
- Note that line 13 instructs Minecraft on how much system memory it can use. The file above will allocate 2 GB of memory. If you'd like to allocate more - like 4 GB, for example - you would need to make the following change:
ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx2G -jar minecraft_server.jar noguiTo:
ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx4G -jar minecraft_server.jar nogui
- Now, you can save your changes to the file and exit.
Start Minecraft Server
Starting the Minecraft server is very easy. Use the following
systemctl command to put it up:
$ sudo systemctl start minecraft@survival
You can confirm the current status of the server to make sure it's up and running with the following command. It should return output that looks like the screenshot below.
$ sudo systemctl status minecraft@survival
Type the following command if you want the Minecraft server to start automatically every time your system reboots:
$ sudo systemctl enable minecraft@survival
To make sure your Minecraft server is listening for incoming connections, use the
nmap command to check the default Minecraft port, which is
$ nmap -p 25565 localhost
As long as
nmap shows that Minecraft is listening on the correct port, you server is good to go. If you'd like to create another server instance, continue on to the next section of our guide. Otherwise, enjoy gaming on your server!
Provision new Minecraft server instance on the same host
If you want to host another instance of Minecraft, most of the work has already been done for us. Now, we just need to copy over some of our existing configuration for the new instance. Since the first server runs on port
25565, we will run the second Minecraft server on port
25566 in this example.
- First, make a new directory for this instance. We'll just call this new server
$ sudo mkdir /opt/minecraft/linuxconfig
- Next, copy over the .jar file from the other Minecraft directory, and accept the terms and conditions again:
$ sudo cp /opt/minecraft/survival/minecraft_server.jar /opt/minecraft/linuxconfig/ $ sudo bash -c "echo eula=true > /opt/minecraft/linuxconfig/eula.txt"
- Use the following command to append a line inside Minecraft's configuration file. This will configure the server instance to run on port
$ sudo bash -c "echo server-port=25566 > /opt/minecraft/linuxconfig/server.properties"
- Give your
minecraftuser ownership of the new directory:
sudo chown -R minecraft /opt/minecraft/linuxconfig/
- Now, use
systemctlto enable the server to start at system boot and start the server:
$ sudo systemctl enable minecraft@linuxconfig $ sudo systemctl start minecraft@linuxconfig
- Verify that the new instance is running correctly:
$ sudo systemctl status minecraft@linuxconfig
- Lastly, use the following content as a reference for the various settings you can use for your server(s). These settings are stored in the
$ sudo nano /opt/minecraft/linuxconfig/server.propertiesFile contents:
max-tick-time=60000 generator-settings= allow-nether=true force-gamemode=false gamemode=0 enable-query=false player-idle-timeout=0 difficulty=1 spawn-monsters=true op-permission-level=4 pvp=true snooper-enabled=true level-type=DEFAULT hardcore=false enable-command-block=false max-players=20 network-compression-threshold=256 resource-pack-sha1= max-world-size=29999984 server-port=25565 server-ip= spawn-npcs=true allow-flight=false level-name=world view-distance=10 resource-pack= spawn-animals=true white-list=false generate-structures=true online-mode=true max-build-height=256 level-seed= prevent-proxy-connections=false use-native-transport=true motd=A Minecraft Server enable-rcon=false
In this guide, we saw how to run a Minecraft server on Ubuntu 20.04 Focal Fossa. We also learned how to configure multiple instances of Minecraft Server to run on a single host.
By following the steps in our guide, you can have a Minecraft server up and running in just a few minutes, with a convenient script configured to make controlling the status of your server a breeze.