Ubuntu 22.04 Minecraft Server Setup

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 22.04 Jammy Jellyfish 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 22.04, we’ve got you covered for that too. Just check out our other guide about how to install Minecraft on Ubuntu 22.04 Jammy Jellyfish 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 22.04 Minecraft Server Setup
Ubuntu 22.04 Minecraft Server Setup
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 22.04 Jammy Jellyfish
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 command line terminal and type the following two commands:

$ sudo apt update
$ sudo apt install wget screen openjdk-18-jdk nmap

Explanation of each package we are installing:

  • wget will be used to download Minecraft server fies
  • screen is for running the Minecraft server in the background
  • openjdk-18-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

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/125e5adf40c659fd3bce3e66e67a16bb49ecc1b9/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..."\015'
    ExecStop=/bin/sleep 5
    ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"\015'
    ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"\015'
    
    
    [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 your port is closed, execute the following ufw command to allow port 25565 through your system firewall.

$ sudo ufw allow to any from any port 25565

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.

  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 tutorial, we saw how to run a Minecraft server on Ubuntu 22.04 Jammy Jellyfish. We also learned how to configure multiple instances of Minecraft Server to run on a single host.




By following the steps in our turorial, 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.