How to Download and Run a Minecraft Server on Linux

In this tutorial, we will show you how to download and run a Minecraft Server on Linux.

Minecraft Server Linux

Minecraft is a super popular multiplayer sandbox game based in an infinitely expanding procedurally generated world. You can have numerous people play with you on one server.

Self-hosting a Minecraft Server on Linux is often cheaper than using something like Realms. Another advantage of hosting your own server is that it gives you full control. You can make any changes you want without having to rely on a third party that restricts what you do.

You can even use this guide to self-host a Minecraft server with VPS providers like DigitalOcean and Vultr.

Best of all, getting a server up and running is straightforward. This guide will focus on the official Minecraft server, which is always compatible with the latest game version.

You can use many other alternative servers, such as Spigot and PaperMC, but we will save them for another guide as the setup steps differ slightly.

If you are running a Raspberry Pi, we recommend following our Pi specific tutorial to set up your Minecraft Server. There are some extra steps required to get the right version of Java on those devices.

Setting up a Minecraft Server on Linux

In the following sections, we will walk you through setting up a Minecraft server on your Linux system.

These steps focus on Debian-based operating systems, but we have included steps for those running other operating systems.

We will be using the terminal for these steps, but don’t worry—it is all pretty straightforward. If you are running a desktop-based system, you can quickly open the terminal by pressing CTRL + ALT + T.

Please note that if you are running this Minecraft server on your home network and want access outside of your home network, you will need to do a couple of things.

First, you must port forward port 25565 to your Linux host. Additionally, you must ensure that this port has been allowed through your firewall.

Preparing your Linux System to run a Minecraft Server

1. If you are running a Debian-based operating system, you should update the package list cache before setting up a Minecraft server.

You can update the package list and upgrade any out-of-date packages by running the following command. If you use a different operating system, such as Fedora, you can skip this step.

sudo apt update
sudo apt upgrade -y

2. Once your operating system is up to date, you will want to install version 21 of the Java runtime environment. At the time of publishing, the Minecraft server requires Java 21 to run on a Linux system.

Use the command relevant to the Linux operating system you are running. We have included the steps for the three major package managers.

In addition to installing Java, we will also install screen, wget, and curl. These will all help make running your server easier.

For Debian, Ubuntu, or other systems using APT

Use the command below if you are running an operating system that uses the apt package manager. The most prominent operating systems you might be familiar with are Ubuntu and Debian.

sudo apt install openjdk-21-jre-headless wget screen curl

For RHEL, Fedora, or Other systems using DNF or YUM

If you are running a Linux operating system, such as Fedora or RHEL, you must use the command below to install the correct version of Java for the Minecraft server.

sudo yum install java-21-openjdk wget screen curl

For Arch Linux and Systems that use pacman

Finally, if you are running Arch Linux, you should use the command below to install the Java runtime on your system.

pacman -S jre21-openjdk-headless wget screen curl

Creating a User to run the Minecraft Server

3. Now that you have the required version of Java for your Linux Minecraft Server, we can proceed to the next step.

In this step, we will create a separate user for the Minecraft server to run under on your Linux system. You will want a separate user for a couple of reasons, one of the most prominent being to separate the server from the rest of your system.

You can create a user called “mcserverlinux” by using the useradd command within the terminal.

sudo useradd -m mcserverlinux

4. With the user created, we will want to add your current user to the “mcserverlinux” group that was created alongside our new user.

You can add your user to this group by using the usermod comamnd.

sudo usermod -aG mcserverlinux $USER

5. Since changed our user’s group’s, you will need to log out or restart your system.

Logging out is as simple as using the following command within the terminal.

logout

Alternatively, restarting is also as simple as using the reboot command.

sudo reboot

6. Once you have logged back into your user, we will use the sudo command again. This time, however, we are using the command so that we can use the terminal as the “mcserverlinux” user we created.

We are doing this to ensure that our new user owns all the files we download and edit, helping reduce the chance of permission issues down the track.

With this command, the “-u” option allows us to specify the user we want to use, and the “-s” option tells it that we want to execute the shell for that user.

sudo -u mcserverlinux -s

Downloading the Minecraft Server to your Linux System

7. Let us now create a directory where we will store our Minecraft server on our Linux system. This is the same folder where you will find the world data and the properties file.

You can create this directory by using the mkdir command.

mkdir ~/minecraftjava

8. Once the directory has been created, change into it by using the cd command.

cd ~/minecraftjava

9. Now that we are in the correct place, we will want to get the download URL for the Minecraft server. Now you could go to the Minecraft server download page and grab the URL yourself, or you can use the command below.

The command below uses the curl command we installed earlier to grab the download page. It then processes this page with “grep” to grab the latest download link.

The result from these commands will be stored within a variable called “DOWNLOAD_URL“.

DOWNLOAD_URL=$(curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -s -L -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; JAVA-UPDATER)" https://minecraft.net/en-us/download/server/ |  grep -o 'https://piston-data.mojang.com/v1/objects/[^"]*')

10. Now, all we need to do to download the latest version of the Minecraft Server to our Linux system is to run the command below.

If you have chosen to get the download URL manually, replace “$DOWNLOAD_URL” with the link.

wget $DOWNLOAD_URL -O server.jar

Running the Server for the First Time

11. You will now have an almost blank directory with a single “server.jar” file within it. When the server runs for the first time, it will generate all the additional files you require.

To run the Minecraft server on your Linux device using Java, run the following command within the terminal.

java -jar server.jar

12. The server will automatically stop after a few seconds with the following message. None of these failed messages are anything to worry about, as we expected them to occur.

We should now have a “server.properties” file and a “eula.txt” file. The properties file will allow you to configure the Minecraft server, and the “eula.txt” file needs to be modified to say that you agree to their terms and conditions.

Starting net.minecraft.server.Main
[14:30:25] [ServerMain/ERROR]: Failed to load properties from file: server.properties
java.nio.file.NoSuchFileException: server.properties
        at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) ~[?:?]
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106) ~[?:?]
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]
        at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:261) ~[?:?]
        at java.base/java.nio.file.Files.newByteChannel(Files.java:379) ~[?:?]
        at java.base/java.nio.file.Files.newByteChannel(Files.java:431) ~[?:?]
        at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420) ~[?:?]
        at java.base/java.nio.file.Files.newInputStream(Files.java:159) ~[?:?]
        at apr.b(SourceFile:62) ~[server-1.21.jar:?]
        at apo.a(SourceFile:141) ~[server-1.21.jar:?]
        at app.<init>(SourceFile:12) ~[server-1.21.jar:?]
        at net.minecraft.server.Main.main(SourceFile:114) ~[server-1.21.jar:?]
        at net.minecraft.bundler.Main.lambda$run$0(Main.java:54) ~[?:?]
        at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]
[14:30:25] [ServerMain/WARN]: Failed to load eula.txt
[14:30:25] [ServerMain/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.

Agreeing to the Terms and Conditions

12. To host your own Minecraft server on Linux, you must agree to the end user licence agreement. This agreement basically stipulates how you can and can’t use the server.

We have linked the EULA above for your convenience. If you are happy with these terms, you can proceed with the tutorial.

To edit the “eula.txt” file, use the following command within the terminal.

nano eula.txt

13. Within this file, you will find the following text and a link to the EULA.

eula=false

Once you have found this option, all you need to do to agree to the terms is replace “false” with “TRUE“, as we have shown below.

eula=TRUE

14. After editing this file, you can save and quit by pressing CTRL + X, Y, and then ENTER.

Configuring the Minecraft Server

15. You will want to configure the Minecraft server before you start it for real on your Linux system.

The way you configure a Minecraft server is through its properties file. You can begin editing this file by running the command below.

nano server.properties

16. With the file open, let us quickly review some key options you can configure for your server. There are plenty of others, but these are the ones we thought many users may want to adjust.

a. One of the first options you may want to consider changing is the difficulty.

Valid options for this are “peaceful“, “easy“, “normal” and “hard“. Setting a world to peaceful will turn off enemy mobs spawning.

difficulty=easy

b. The next option you may want to adjust is the game mode for your Minecraft server. By default, this is set to “survival“, which is probably the most common way users will play Minecraft.

The options that you can use here are “survival“, “creative“, and “adventure“.

gamemode=survival

c. You may want to use a specific seed for the world generation. By default, Minecraft will automatically generate a random seed when it first starts on your Linux system.

Using a specific seed allows the world to generate in a specific way. There are many sites that provide you with seeds that you can use.

level-seed=

d. The Minecraft server will allow PvP combat by default. If you don’t want players to be able to attack each other change the following option to “false“.

pvp=true

e. One problem with the Minecraft server is that it doesn’t allow you to set a password. Instead, you must enable whitelisting and individually allow users.

You can enable whitelisting by finding the following option and changing “false” to “true“.

white-list=false

After enabling the white list, you will want to add the following to the bottom of the file.

Replace “username1” with the username of the user you want to allow access to this server. Additional users can be added by using a comma, followed by their username.

white-list-players=username1,username2

17. Once you have finished configuring this file, save and quit by pressing CTRL + X, Y and then ENTER.

Launching the Minecraft Server on Linux

18. With everything configured, you can start the Minecraft server on Linux by running the following command. Depending on your system, you will want to change two options.

  • -Xms1024M: This value allows you to specify the amount of memory that the Minecraft server should consume on your Linux system.

    The more players or mods you have the higher this value you should be. With the value we are using the starting memory consumption is set to “1024” megabytes of RAM (1GB).
  • -Xmx2048M: The maximum amount of RAM that the server can consume. Set this to the highest value you want the server to consume. For our example below we have it set to “2048” megabytes (2GB).
java -Xms1024M -Xmx2048M -jar server.jar

19. You should now successfully have your Minecraft Server up and running on your Linux system. With the server running you should be able to use the terminal to give your user “op” privileges.

Your server won’t automatically start at the moment. Follow this guide to learn how to make your Minecraft server start when Linux does.

Starting your Minecraft Server at Boot

Now that you have the Minecraft server downloaded and running on your Linux system, you may want to get it to start at boot.

To get the server to start at boot, we will write a systemd service file. This service will start the server and attempt to restart it if it ever crashes automatically.

These steps will work on any Linux system that implements the systemd system manager. Which at this stage is the vast majority of systems.

Writing a Script to Start the Server

1. Before we begin writing the scripts that will start and stop the Minecraft server, you will want to be running as the “mcserverlinux” user.

If you aren’t, you can change to this user by running the command below within the terminal.

sudo -u mcserverlinux -s

2. You can now begin writing the “start_server.sh” bash script by running the command below.

We are using the nano text editor as it is relatively simple for beginners.

nano /home/mcserverlinux/minecraftjava/start_server.sh

3. Within this file, you will want to add the following lines.

These lines basically set up the Minecraft Server on your Linux device within a screen. We also allow it so that we can interact with the screen session using the root user.

There are two placeholders that you will want to update within this file.

  • -Xms1024M: Update this value to represent the minimum amount of memory that you want to be allocated to your Minecraft server. This value should be in megabytes.

    For example, if you wanted to allocate 2GB of RAM, you would change this to “-Xms2048M“.
  • -Xmx2048M: Change this value to the maximum amount of RAM the server should consume. Like the minimum RAM value, this is also written in megabytes.

    For example, if you want to set the maximum amount of RAM to 4GB, you would use the value “-Xmx4096M“.
#!/usr/bin/env bash

SERVER_PATH=/home/mcserverlinux/minecraftjava/

/usr/bin/screen -dmS mcjava /bin/bash -c "/usr/bin/java -Xms1024M -Xmx2048M -jar ${SERVER_PATH}server.jar"
/usr/bin/screen -rD mcjava -X multiuser on
/usr/bin/screen -rD mcjava -X acladd root

4. After writing the start server script, you can save quit by pressing CTRL + X, Y, and then ENTER.

5. We can make this new script executable by using the chmod command.

chmod +x /home/mcserverlinux/minecraftjava/start_server.sh

Creating a Script to Stop the Minecraft Server

7. Your next step is to write a script that will send a “stop” command to the Minecraft server. Sending this command will allow the server to save and cleanly shut down.

Begin writing this script by using the following command.

nano /home/mcserverlinux/minecraftjava/stop_server.sh

7. Within this file, enter the following lines. This script is super simple and uses screen to send a message to the server. You could potentially extend this down track to send a message before the server is shut down.

#!/usr/bin/env bash

/usr/bin/screen -Rd mcjava -X stuff "stop \r"

8. Now that you have the script written, save and quit by pressing CTRL + X, Y, and then ENTER.

9. Like the start script, we will need to use the chmod command to give this script execute privileges.

chmod +x /home/mcserverlinux/minecraftjava/stop_server.sh

Writing a Service to Manage your Linux Minecraft Server

10. At this point, we are done with the “mcserverlinux” user. You can exit and return to your previous user by running the following command.

exit

11. We can now begin writing the service file to manage the Minecraft Server on your Linux system.

To start writing the file, run the following command in the terminal.

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

12. In this file, type out the following lines. There is nothing you need to modify in this, as the start and stop scripts handle all the work.

[Unit]
Description=Minecraft Java Server
Wants=network-online.target
After=network-online.target

[Service]
Type=forking
User=mcserverlinux
Group=mcserverlinux
ExecStart=/usr/bin/bash /home/mcserverlinux/minecraftjava/start_server.sh
ExecStop=/usr/bin/bash /home/mcserverlinux/minecraftjava/stop_server.sh
WorkingDirectory=/home/mcserverlinux/minecraftjava/
Restart=always
TimeoutStartSec=600

[Install]
WantedBy=multi-user.target

13. After writing the service file, save and quit by pressing CTRL + X, Y, and then ENTER.

14. To get the Minecraft server to start when our Linux system starts, we must “enable” the service we just wrote.

Enabling the service is as simple as running the following command within the terminal.

sudo systemctl enable minecraftserver

15. With the service now enabled, you can start the server up running the command below.

sudo systemctl start minecraftserver

Accessing your Minecraft Server Command Line

16. To access your Linux Minecraft Servers command line interface, run the following command in the terminal.

This will restore the screen we placed the server into when the service started.

sudo screen -r mcserverlinux/mcjava

17. Within this interface, you can run as many commands to your server as you would like.

For example, we could run the following command if we wanted to give the user “pimylifeup” OP privileges.

op pimylifeup

18. Once you are done, you must detach the screen session so the service can interact with it again. This step is super important and cannot be skipped.

To detach the virtual screen, press CTRL + A, then CTRL + D.

Manually Updating your Minecraft Server on Linux

Whenever Minecraft updates its game client, you must also update your server so that you can continue to play.

Luckily, updating to the latest version of the Minecraft server on your Linux system is relatively simple.

1. Your first step is to stop the currently running server. You can’t update the server if it is in use.

If you are using the service file we wrote earlier in this guide, you can easily stop your Linux Minecraft server by running the command below.

sudo systemctl stop minecraftserver

2. Next, you must change to the “mcserverlinux” user that owns the Minecraft server by using the following command in the terminal.

sudo -u mcserverlinux -s

3. Now change to where the Minecraft server is stored. If you followed our guide exactly, you should be able to use the command below.

cd ~/minecraftjava

4. We can now use our bit of curl and grep magic to grab the download link to the latest version of the Minecraft server.

DOWNLOAD_URL=$(curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -s -L -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; JAVA-UPDATER)" https://minecraft.net/en-us/download/server/ |  grep -o 'https://piston-data.mojang.com/v1/objects/[^"]*')

5. By running the command below, the wget command will download the latest version of the Minecraft server to your Linux system.

This command should replace the existing “server.jar“.

wget $DOWNLOAD_URL -O server.jar

6. We have now finished updating the Minecraft server so we can exit and return to your user.

exit

7. Finally, start the Minecraft server back up on your machine by running the following command.

sudo systemctl start minecraftserver

Conclusion

Hopefully, at this stage, you will have successfully set up and run a Minecraft server on your Linux system.

Throughout this guide you have seen how easy it is to install and run the server for Minecraft. We have walked you through installing Java and shown you how to easily download the latest version of the game server.

Please feel free to post a comment below if you have any questions about running this game server.

If you found this tutorial to be helpful, we highly recommend that you check out our many other game server tutorials.

Leave a Reply

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