Advance

Tutorial Create A Minecraft Server On Ubuntu 21.04

Tutorial Create A Minecraft Server On Ubuntu 21.04
5
(1)

Minecraft is one of the most popular games in the world. This sandbox video game released in 2019 and is well known for its limitless adventures. Gamers who are mad at build, explore, craft, and survive in a block 3D-generated world will be addicted to Minecraft. To start gaming with this second best-selling video game, you need to create your own Minecraft server. So, join us with this article to review Tutorial Create A Minecraft Server On Ubuntu 21.04. Order your preferred package on Eldernode to purchase your own Ubuntu VPS Hosting.

How To Create A Minecraft Server On Ubuntu 21.04

If you are interested in mine, craft, and Minecraft with other players, this guide helps you to learn How to install software packages, configure the server, and deploy to the game. As a player, you can improve your problem-solving abilities, exercise your creativity. Also, if you believe in games with educational benefits, Minecraft is what you want.

Recommended Article: Tutorial Configure Redis on Linux Ubuntu 20.04

Prerequisites to Make Minecraft Server on Ubuntu 21.04

To let this tutorial work better, please consider the below Prerequisites:

_ A non-root user with Sudo privileges.

_ To set up, follow our Initial server setup on Ubuntu 21.04.

_ At least 4GB Ram.

How To Install Minecraft Server on Ubuntu 21.04

To know exactly who is connecting with and play with you or your child, you need to setup your own server. It means that you are totally in charge of your gaming experience. Since Ubuntu is known for its ease of use, Ubuntu 21.04 Hirsute Hippo is a top choice for hosting a Minecraft server. Stay with us to walk through the required steps to make a Minecraft server on Ubuntu 21.04.

Step 1:

As is expected, you will start with installing the required packages since the Minecraft server needs them to be run. So, open a terminal and type:

sudo apt update
sudo apt install git build-essential

In this way, the required packages to build mcrcon tool will be installed.

Step 2:

In this step, you need to install Java. Minecraft requires Java 8 or higher but since it does not need a graphical user interface, you can install the headless version of Java. Use the following command to do this:

sudo apt install openjdk-11-jre-headless

Then, you can check the version you have installed by running the command below:

java -version

Step 3:

Now, you need to create a Minecraft user. But according to security reasons, Minecraft should not be run under the root user. So, create a new system user and group with home directory /opt/minecraft. The user will have the minimum necessary permissions to run the Minecraft server:

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

Since you will not set a password for this user, the user will not be able to log in via SSH and cannot be compromised.

Note: To change to the Minecraft user, you will need to log in to the server as root or user with Sudo privileges.

Step 4:

It is time to Install Minecraft on Ubuntu. But first, switch to the minecraft user:

sudo su - minecraft

Then, you need to create three new directories inside the user home directory. Backup, tools, and server. Let’s see the definition of each one and then create them:

1) The backup directory

To store your Minecraft server backups, you need this directory. Also, you can synchronize this directory to your remote backup server.

2) The tools directory

The second directory holds the mcrcon client and the backup script.

3) The server directory

The server directory contains the actual Minecraft server and its data.

You can create all these three directories using the command below:

mkdir -p ~/{backups,tools,server}

Step 5:

To download and compile mcron, go to GitHub and download the source code. Then, you can build the mcron binary. CON is a protocol that allows you to connect to the Minecraft servers and execute commands.

Clone the Tiiffi/mcrcon repository from GitHub to the ~/tools/mcron directory:

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

Then, switch to the mcron directory and build the utility:

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

When finished, use the command below to verify that mcrcon has been successfully compiled by printing its version:

./mcrcon -v

Minecraft Server Mods

To download the Minecraft server, there are several Minecraft server mods such as Craftbukkit or Spigot. You can use them to add plugins to your server and further customize and tweak the server settings. In this section, you will learn to install Mojang official vanilla Minecraft server. So, you will be able to use the instructions to install any other desired server mode.

To get the download link of the latest Minecraft server’s Java archive file (JAR), go to the Minecraft download page. Then, download the jar file in the ~/server directory with wget :

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

How to Configure Minecraft Server on Ubuntu 21.04

After a successful download, you can start the Minecraft server by switching to the ~/server directory:

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

At the first start, the server executes some operations, creates the server.properties and eula.txt files, and stops.

The output asks you to agree to the Minecraft EULA. Open the eula.txt file and change eula=false to eula=true:

nano ~/server/eula.txt

Now, you can save and close the file.

To enable the rcon protocol and set the rcon password, open the server.properties file:

nano ~/server/server.properties

To update the values, find the lines in the output.

Note: If you do not want to connect to the Minecraft server from remote locations, make sure the rcon port is blocked by your firewall. Change the strong-password to a more secure password.

How to Create Systemd Unit File

You can create a Systemd unit file and run Minecraft as a service. It is recommended instead of starting the Minecraft server manually. Follow the below path to do this:

1- Switch back to your Sudo user by typing exit.

2- Open your text editor and create a file named minecraft.service in the /etc/systemd/system/ directory.

sudo nano /etc/systemd/system/minecraft.service

Then, paste the following configuration:

/etc/systemd/system/minecraft.service
[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 strong-password stop
[Install]  WantedBy=multi-user.target

Then, you can modify the Xmx and Xms flags according to your server resources. The Xmx flag defines the maximum memory allocation pool for a Java virtual machine (JVM), while Xms defines the initial memory allocation pool. Also, make sure that you are using the correct rcon port and password.

Finally, save the file and to reload the systemd manager configuration, run:

sudo systemctl daemon-reload

Now, you can run the following command to start the Minecraft server by typing:

sudo systemctl start minecraft

When started for the first time, the service will generate several configuration files and directories, including the Minecraft world. Run the command below to check the service status:

sudo systemctl status minecraft

You can enable the Minecraft service to be automatically started at boot time. So, run:

sudo systemctl enable minecraft
Recommended Article: How To Install PiVPN On Ubuntu 20.04 LTS

How to Adjust Firewall

If the firewall is enabled on your system, and you want to access the Minecraft server from the outside of your local network, you need to open port 25565:

sudo ufw allow 25565/tcp

How to Configure Backups

To back up the Minecraft server automatically, you need to create a backup shell script and cronjob. First, switch to the minecraft:

sudo su - minecraft

Open your favorite text editor and create the following file:

nano /opt/minecraft/tools/backup.sh

Paste the following configuration:

/opt/minecraft/tools/backup.sh
#!/bin/bash    function rcon {  /opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password "$1"  }    rcon "save-off"  rcon "save-all"  tar -cvpzf /opt/minecraft/backups/server-$(date +%F-%H-%M).tar.gz /opt/minecraft/server  rcon "save-on"    ## Delete older backups  find /opt/minecraft/backups/ -type f -mtime +7 -name '*.gz' -delete

Save the file and make the script executable :

chmod +x /opt/minecraft/tools/backup.sh

Then, to run once in a day automatically at a fixed time, you need to create a cron job. To open the crontab file, run:

crontab -e

For example, if you wish to run the backup script every day at 8:00, you need to paste the following line:

0 8 * * * /opt/minecraft/tools/backup.sh

How to Access Minecraft Console on Ubuntu 21.04

You can use the mcrcon utility to access the Minecraft Console. To do this, specify the host, rcon port, rcon password and use the -t switch which enables the mcrcon terminal mode:

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

The output should report your login. You can type ”Q” to quit.

Note: Anytime you access Minecraft Console from a remote location, the rcon port should not be blocked. But if you connect to the Minecraft console regularly, create a bash alias instead of typing this log command.

Conclusion

In this article, you learned How To Create A Minecraft Server On Ubuntu 21.04. Now, you know how to make a Minecraft server on your Ubuntu server and set up a daily backup. To keep your server safe and happy, you must invite people you know to play on your server. Once your Minecraft server is setup, you can use your admin powers for an advantage, and bestow those powers on to your fellow gaming buddies. However, you can create a private server for just you and your friends, or make it public for everyone to access. Start your Minecraft adventure by launching your Minecraft client and connect to the server.

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

View More Posts
Marilyn Bisson
Content Writer
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

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

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day