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
Ubuntu 20.04 Minecraft Server Setup
Ubuntu 20.04 Minecraft Server Setup
Software Requirements and Linux Command Line Conventions
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 sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Install Prerequisites

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
  • wget will be used to download Minecraft server fies
  • screen is for running the Minecraft server in the background
  • default-jdk is a Java package that Minecraft needs in order to run
  • nmap will 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

SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Install Minecraft server

  1. 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/minecraft directory. For this first server instance, let's call it survival and create the following directory:
    $ sudo mkdir /opt/minecraft/survival
    
  2. 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.
    Copy the link location from the Minecraft download page
    Copy the link location from the Minecraft download page


  3. 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
    
    Use wget to download the server java file
    Use wget to download the server java file
  4. 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" 
    
  5. Lastly, we need to give our minecraft user 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.

  1. Start by creating the following file with nano or your preferred text editor:
    $ sudo vi /etc/systemd/system/minecraft@.service 
    
  2. 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


  3. 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:

    From:
    ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui
    
    To:
    ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx4G -jar minecraft_server.jar nogui
    
  4. Now, you can save your changes to the file and exit.
    SystemD script for Minecraft
    SystemD script for Minecraft

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
Checking the status of the Minecraft server
Checking the status of the Minecraft server

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 25565:

$ nmap -p 25565 localhost
nmap shows that Minecraft is listening on port 25565
nmap shows that Minecraft is listening on port 25565

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


SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


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.

  1. First, make a new directory for this instance. We'll just call this new server linuxconfig:
    $ sudo mkdir /opt/minecraft/linuxconfig
    
  2. 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" 
    
  3. Use the following command to append a line inside Minecraft's configuration file. This will configure the server instance to run on port 25566:
    $ sudo bash -c "echo server-port=25566 > /opt/minecraft/linuxconfig/server.properties"
    
  4. Give your minecraft user ownership of the new directory:
    sudo chown -R minecraft /opt/minecraft/linuxconfig/
    


  5. Now, use systemctl to enable the server to start at system boot and start the server:
    $ sudo systemctl enable minecraft@linuxconfig
    $ sudo systemctl start minecraft@linuxconfig
    
  6. Verify that the new instance is running correctly:
    $ sudo systemctl status minecraft@linuxconfig
    
  7. 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 server.properties file inside /opt/minecraft/linuxconfig.
    $ sudo nano /opt/minecraft/linuxconfig/server.properties
    
    File 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
    

Conclusion

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.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions