Ubuntu Minecraft Server Java Edition

In this tutorial, I will take you through the process of setting up a Java edition Minecraft server on Ubuntu.

Minecraft Java Server on Ubuntu

Setting up a private Minecraft server on Ubuntu is straightforward, especially if you have experience using a Linux-based operating system.

The number of people the server can handle will vary heavily depending on the specifications of your computer. Since the Minecraft server is RAM hungry, I recommend having a generous amount of memory if you wish to host many people.

You will need to investigate port forwarding if you wish to allow users outside your local network to connect to the server. You may also want to investigate using additional security features to help protect your system, such as UFW.

This tutorial is for running Minecraft on an Ubuntu server or Ubuntu desktop. If you want to run the server on a Raspberry Pi, we recommend following our dedicated Raspberry Pi Minecraft server tutorial. With that said, this tutorial should still work on the Raspberry Pi.

Table of Contents

Installing the Java Minecraft Server on Ubuntu

The process of installing the Java Minecraft server on Ubuntu is pretty straightforward. Of course, we will be using the server version of Ubuntu, but there is no reason why you cannot do this on the desktop version of Ubuntu.

This tutorial has been tested on Ubuntu 20.04, but should also work on Ubuntu 18.04.

Throughout this tutorial, we will be using the terminal and a range of different commands. The commands are not overly difficult to comprehend, so you should be fine even if you are new to using the command line.

1. Update Ubuntu, so it has the latest packages available by entering the following into the terminal.

sudo apt update
sudo apt upgrade

2. Next, we will need to install Java so we can run the Minecraft server. To install the OpenJDK version 17 jre package, run the following command.

sudo apt install openjdk-17-jre-headless

3. You can verify the Java has been installed correctly by entering java -version into the terminal.

dev@pimylifeup:~$ java -version
openjdk version "17.0.3" 2022-04-19
OpenJDK Runtime Environment (build 17.0.3+7-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 17.0.3+7-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing)

4. For our next step, we need to create a user that our Ubuntu Minecraft server will run under.

We will call this user “mcserver” and use the “-m” option so that it generates a home directory for the user.

sudo useradd -m mcserver

5. After creating this new user we should add it’s group to our current user. This will allow us to much easier read and edit files within their new home directory.

You can add the “mcserver” group to our current user by using the following command.

sudo usermod -a -G mcserver $USER

6. As we have made changes to our users groups you will need to log off and log back in for the changes to take affect.

You can easily log out of Ubuntu by using the following command in the terminal.

logout

7. We will need to create a directory to store our Minecraft server files. Afterward, we change directory into our new directory.

sudo mkdir /home/mcserver/minecraft
cd /home/mcserver/minecraft

8. Now, we need to use wget to download the latest version of the Minecraft server jar file. You will need to go to the Minecraft server download page and copy the link to the file for the latest version.

Java Minecraft Server Jar Download Link

The final command should look similar to the one below.

sudo wget https://launcher.mojang.com/v1/objects/e00c4052dac1d59a1188b2aa9d5a87113aaf1122/server.jar

9. Depending on your internet speed, the server file should download relatively quickly.

You can use the ls command to view the contents of your directory, which should contain the server.jar file.

dev@pimylifeup:/home/mcserver/minecraft$ ls
server.jar

We are now ready to launch the server and be one step closer to connecting and playing in our own Minecraft world.

Starting the Server

This section will take you through a few brief steps to starting the server for the first time.

1. To launch the server, we need to enter a Java command that specifies a few settings and references the server jar file.

  • -Xms allows you to specify the initial size of the memory allocation pool. The number is in bytes unless followed by a letter. K or k for kilobytes. M or m for megabytes.
  • -Xmx allows you to specify the maximum size of the memory allocation pool. The number is in bytes unless followed by a letter. K or k for kilobytes. M or m for megabytes.
  • -jar is followed by the jar file that you wish to run.
  • nogui we set this option as we do not need any GUI (Graphical User Interface) as we’re running the server from the terminal.

Since a Minecraft server can use a lot of memory, we set the server to have a large minimum allocation (1024M). We double the minimum for the maximum memory allocation (2048M).

The command to launch the server should be similar to the example below.

sudo java -Xms1024M -Xmx2048M -jar /home/mcserver/minecraft/server.jar nogui

2. As soon as you start the server, it will stop as you will need to agree to a EULA to proceed.

[10:08:07] [ServerMain/INFO]: Building unoptimized datafixer
[10:08:09] [ServerMain/ERROR]: Failed to load properties from file: server.properties
[10:08:09] [ServerMain/WARN]: Failed to load eula.txt
[10:08:09] [ServerMain/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info

3. To accept the EULA, you need to open the file in a text editor, such as nano.

sudo nano eula.txt

4. Inside this file, find and change the line eulu=false to eula=TRUE.

eula=TRUE

Once you have made the changes to the file, save and exit by pressing CTRL + X, then Y.

5. Run the java command again to start the server, this time, it should start without any issues.

sudo java -Xms1024M -Xmx2048M -jar /home/mcserver/minecraft/server.jar nogui

6. The server should be running and accessible within a few minutes.

Connecting to the Server

Connecting to the server should be relatively easy as long as you do not have problematic firewalls, routers, and other possible network issues.

1. To connect to the server, you will first need the IP. You can use the hostname command on the server to get the IP.

hostname -I

The command should return an IP that is similar to the example below.

192.168.0.56

2. You now need to load the Minecraft Java client on a computer within the same local network as the server.

3. Once the game has loaded, navigate to the “Multiplayer” menu.

Minecraft Java Edition Main Menu

4. Select either “Direct Connection” or “Add Server”. For this tutorial, I will select “Direct Connection”.

Minecraft Java Edition Multiplayer

5. On the next screen, enter the server’s IP into the server address field. Afterward, click “Join Server“.

Minecraft Java Edition Direct Connection

5. You should now load into the server successfully. The terminal on your server should also indicate “user joined the game”.

Minecraft Java Edition New Server

Configuring the Server

You will likely want to configure the server to fit your needs a little better. For example, you may want to set your user as OP, which allows them to perform admin commands while in-game. You may also want to edit the server properties such as the maximum amount of players, spawning creators, and much more.

Making a User OP

To help administrate the server from within the game, you will likely want to set your user as OP. Luckily, you can easily do this from the terminal on your Ubuntu machine.

After you have launched the Minecraft server and the terminal is accepting input. Enter the following line to make your user OP. Replace the username with the username of your Minecraft account.

op username

You should get the following output in the terminal to confirm that the user is now OP.

[04:28:38] [Server thread/INFO]: Made username a server operator

You can confirm the change is successful by changing the time to daytime using the in-game chat. You can bring the chat menu up by pressing the t key.

/time set 0

Editing Server Properties

You can edit a range of server properties that will tweak the game’s behavior. For example, you can change the game mode, max players, PVP, simulation distance, NPCs, and more.

To load the server properties file, simply enter the following line into the terminal.

sudo nano /home/mcserver/minecraft/server.properties

Inside the file, you can edit any of the available properties. Most of them are self-explanatory, but others may require more information. You can read more about Minecraft server properties if you require more information.

Once you are done editing the properties file, you will need to make sure you restart your server for the changes to take effect.

Boot on Startup

We will need to do a few extra steps to have the Minecraft server boot on startup with Ubuntu. Luckily they are pretty straightforward.

1. Our first task is to ensure that our “mcserver” user owns all of the files within its directory.

Until now, we have been using the superuser to run the server. However, with the service we will be writing, we will instead rely on our “mcserver” user to run our Ubuntu Minecraft Java server.

Take ownership of all the files by using the following command within the terminal.

sudo chown -R mcserver:mcserver /home/mcserver/

2. First, we will need to create a service for our Minecraft server. To do this, enter the following command into the terminal.

sudo nano /lib/systemd/system/minecraftserver.service

3. Inside this file, you must enter the following configuration.

This file tells the service manager how to run our Java Minecraft server. For example, we are telling the system to run our service using the “mcserver” user we created earlier.

[Unit]
Description=Minecraft

[Service]
User=mcserver
Group=mcserver
Restart=on-abort
WorkingDirectory=/home/mcsesrver/minecraft/
ExecStart=/usr/bin/java -Xms1024M -Xmx2048M -jar /home/mcsesrver/minecraft/server.jar nogui

[Install]
WantedBy=multi-user.target

Once done, save the file by pressing CTRL + X then Y followed by ENTER.

4. After creating the service, you will want to enable it. You can enable the service by running the command below.

sudo systemctl enable minecraftserver.service

5. You should now be able to start the Minecraft server by running the following command.

sudo systemctl start minecraftserver.service

6. You can check the server’s status by running the following command. It is great for debugging, especially if the server fails to launch.

sudo systemctl status minecraftserver.service

You should get an output that looks similar to the example below.

dev@pimylifeup:/home/mcsesrver/minecraft$ sudo systemctl status minecraftserver.service
● minecraftserver.service - Minecraft
     Loaded: loaded (/lib/systemd/system/minecraftserver.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-06-26 05:10:15 UTC; 7s ago
   Main PID: 43824 (java)
      Tasks: 26 (limit: 4608)
     Memory: 458.1M
     CGroup: /system.slice/minecraftserver.service
             └─43824 /usr/bin/java -Xms1024M -Xmx2048M -jar /home/dev/minecraft/server.jar nogui

Jun 26 05:10:15 pimylifeup systemd[1]: Started Minecraft.
Jun 26 05:10:15 pimylifeup java[43824]: Starting net.minecraft.server.Main
Jun 26 05:10:19 pimylifeup java[43824]: [05:10:19] [ServerMain/INFO]: Building unoptimized datafixer

7. Lastly, you can also stop the server by running the following command.

sudo systemctl stop minecraftserver.service

8. You can confirm the server is now starting at boot by rebooting Ubuntu.

sudo reboot

Once Ubuntu is running again, you should be able to enter your Minecraft server without having to enter any commands. Depending on the speed of your computer, it may take a few minutes to start.

Conclusion

You should now have a fully functioning Minecraft Java server running on Ubuntu. Depending on your system’s specifications, you should have a server capable of handling quite a few people. You can also tweak the server properties if you find the server is not up to expectations.

This tutorial covered all the basics for setting up the server on a local network. If you want to open it up to the internet, you will need to investigate using port forwarding. However, you should be aware that port forwarding does increase the risk of security issues.

Please let us know if you notice a mistake or an important topic is missing from this guide.

4 Comments

  1. Avatar for Tommy Welle
    Tommy Welle on

    Thank you for this guide. I went on installing this without knowing i needed the bedrock version. Now i think i have 2 servers running and i was wondering how do i uninstall the Java version? Im a Windows user so this is totally ned for me and i really just copy paste code :p

    1. Avatar for Emmet
      Emmet on
      Editor

      Hi Tommy,

      Glad you liked this tutorial and that’s definitely a mistake anyone could make.

      Uninstalling the server is fairly straightforward. Assuming you followed the tutorial to the end, these steps should remove it.

      1. First you will want to disable the service so that it wont attempt to automatically start it when Ubuntu restarts.

      sudo systemctl enable minecraftserver.service

      2. Next, you must stop the service by using the following command.

      sudo systemctl stop minecraftserver.service

      3. With the Minecraft server now stopped we can remove the service entirely from Ubuntu by deleting the file we wrote within the tutorial.

      sudo rm /lib/systemd/system/minecraftserver.service

      4. Finally, you can clean up the directory where we saved the Java Minecraft server to by running the command below.

      sudo rm -r -f /home/mcsesrver/minecraft/

      This command will remove the “minecraft” directory and all files and directories within it.

      Hopefully that helps you out.

      Kind regards,
      Emmet

  2. Avatar for charlag
    charlag on

    You have a typo, it says “mcsesrver” in the unit file everywhere.

    Otherwise, great instructions!

    1. Avatar for Emmet
      Emmet on
      Editor

      Hi Charlag,

      Thank you very much for pointing out that typo. I have now corrected it!

      I am glad that the tutorial was helpful for you.

      Cheers,
      Emmet

Leave a Reply

Your email address will not be published. Required fields are marked *