Login

    How to install Minecraft Server on Ubuntu 20.04 LTS

    How to install Minecraft Server on Ubuntu 20.04 LTS

    Minecraft is an open world and sandbox video game developed by Mojang Studios. With Minecraft, you can build anything you can imagine with unlimited resources in Creative mode. It allows you to play online with friends as well as in single-player mode. It is one of the best video games around the world. You can create your own Minecraft server to play with your friends and play together.eval(ez_write_tag([[728,90],’howtoforge_com-box-3′,’ezslot_6′,106,’0′,’0′]));

    In this tutorial, we will show how to set up your own Minecraft server on Ubuntu 20.04 LTS.eval(ez_write_tag([[580,400],’howtoforge_com-medrectangle-3′,’ezslot_2′,121,’0′,’0′]));

    Prerequisites

    • A server running Ubuntu 20.04 with a minimum of 4 GB RAM.
    • A root password is set up on your server.

    Getting Started

    First, you will need to update your system with the latest version. You can update them with the following command:

    apt-get update -y
    apt-get upgrade -y

    Once your system is updated, install some required dependencies with the following command:

    apt-get install git build-essential -y

    Once you are finished, you can proceed to the next step.

    Install Java

    Minecraft is written in Java language, so you will need to install the headless version of Java in your system. You can install it with the following command:

    apt-get install openjdk-11-jre-headless -y

    Once installed, you can verify the installed version of Java with the following command:

    java -version

    You should get the following output:

    openjdk version "11.0.7" 2020-04-14
    OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
    OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
    

    Install Minecraft Server

    Before starting, you will need to create a separate user for Minecraft. You can create it with the following command:

    useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft

    Next, switch the user to Minecraft with the following command:eval(ez_write_tag([[580,400],’howtoforge_com-medrectangle-4′,’ezslot_1′,108,’0′,’0′]));

    su - minecraft

    Next, create required directories for Minecraft with the following command:

    mkdir ~/backups ~/tools ~/server

    Install mcrcon

    Next, you will need to install mcrcon in your system. mcrcon is RCON client written in C that allows you to connect to the Minecraft servers.

    You can download the mcrcon to the ~/tools directory:

    git clone https://github.com/Tiiffi/mcrcon.git ~/tools/mcrcon

    Next, change the directory to the mcrcon and build the tool with the following command:

    cd ~/tools/mcrcon
    gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c

    Once installed, verify the mcrcon with the following command:

    ./mcrcon -v

    You should see the following output:

    mcrcon 0.7.1 (built: Jul  2 2020 07:44:45) - https://github.com/Tiiffi/mcrcon
    Bug reports:
    	tiiffi+mcrcon at gmail
    	https://github.com/Tiiffi/mcrcon/issues/
    

    Download and Configure Minecraft Server

    First, download the latest version of Minecraft server to the ~/server directory:

    wget https://launcher.mojang.com/v1/objects/a0d03225615ba897619220e256a266cb33a44b6b/server.jar -P ~/server

    Next, change the directory to ~/server directory and start the Minecraft server:

    cd ~/server
    java -Xmx1024M -Xms1024M -jar server.jar nogui

    You should see the following error:

    [07:46:12] [main/ERROR]: Failed to load properties from file: server.properties
    [07:46:12] [main/WARN]: Failed to load eula.txt
    [07:46:12] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
    

    This is because you need to agree to the Minecraft EULA. You can do that by editing the file eula.txt:

    nano ~/server/eula.txt

    Change the line eula=false to eula=true as shown below:

    eula=true
    

    Save and close the file when you are finished. Next, edit the server.properties file and set the rcon password:

    nano ~/server/server.properties

    Change the following lines:

    rcon.password=your-password
    enable-rcon=true 
    

    Save and close the file when you are finished.

    Create a Systemd Unit File for Minecraft

    Next, you will need to create a systemd service file to manage the Minecraft service. You can create it with the following command:

    nano /etc/systemd/system/minecraft.service

    Add the following lines:

    [Unit]
    Description=Minecraft Server
    After=network.target
    
    [Service]
    User=minecraft
    Nice=1
    KillMode=none
    SuccessExitStatus=0 1
    ProtectHome=true
    ProtectSystem=full
    PrivateDevices=true
    NoNewPrivileges=true
    WorkingDirectory=/opt/minecraft/server
    ExecStart=/usr/bin/java -Xmx1024M -Xms1024M -jar server.jar nogui
    ExecStop=/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p your-password stop
    
    [Install]
    WantedBy=multi-user.target
    

    Save and close the file when you are finished. Then, reload the systemd daemon with the following command:

    systemctl daemon-reload

    Next, start the Minecraft service and enable it to start at system reboot with the following command:

    systemctl start minecraft
    systemctl enable minecraft

    You can now verify the status of Minecraft service with the following command:

    systemctl status minecraft

    You should get the following output:

    ? minecraft.service - Minecraft Server
         Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
         Active: active (running) since Thu 2020-07-02 08:05:24 UTC; 1min 0s ago
       Main PID: 11704 (java)
          Tasks: 30 (limit: 4691)
         Memory: 1.0G
         CGroup: /system.slice/minecraft.service
                 ??11704 /usr/bin/java -Xmx1024M -Xms1024M -jar server.jar nogui
    
    Jul 02 08:06:06 ubuntu2004 java[11704]: [08:06:06] [Worker-Main-2/INFO]: Preparing spawn area: 94%
    Jul 02 08:06:06 ubuntu2004 java[11704]: [08:06:06] [Server thread/INFO]: Preparing spawn area: 95%
    Jul 02 08:06:07 ubuntu2004 java[11704]: [08:06:07] [Worker-Main-2/INFO]: Preparing spawn area: 96%
    Jul 02 08:06:07 ubuntu2004 java[11704]: [08:06:07] [Worker-Main-2/INFO]: Preparing spawn area: 96%
    Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Worker-Main-2/INFO]: Preparing spawn area: 99%
    Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Server thread/INFO]: Time elapsed: 26283 ms
    Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Server thread/INFO]: Done (26.613s)! For help, type "help"
    Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Server thread/INFO]: Starting remote control listener
    Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [Server thread/INFO]: Thread RCON Listener started
    Jul 02 08:06:08 ubuntu2004 java[11704]: [08:06:08] [RCON Listener #1/INFO]: RCON running on 0.0.0.0:25575
    

    Your Minecraft server is now started and listening on port 25575. You can verify it with the following command:

    netstat -pnltu | grep 25575

    You should get the following output:

    tcp6       0      0 :::25575                :::*                    LISTEN      10584/java 
    

    Access Minecraft Console

    You can now access the Minecraft with mcrcon utility. You can do it by specifying the password, host and port as shown below:

    /opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p your-password -t

    Once connected successfully, you should get the following output:

    Logged in. Type 'quit' or 'exit' to quit.
    >
    

    Conclusion

    In the above guide, you learned how to install Minecraft server on Ubuntu 20.04. You can now download and install Minecraft client, connect to the Minecraft server and start playing with it. Feel free to ask me if you have any questions.

    Leave a Reply