bannerAds
Global
language language

Product

Doc

Support

Menu 

SiliCloud Help Document Center

search

Popular search terms

How To Install Minecraft Server On Ubuntu 18.04

Update time 2023-02-19 21:17  Version v1.2
I want feedback 
Collect My collection

Minecraft is one of the most popular games of all time. It's a sandbox video game that allows players to explore infinite worlds and build everything from simple houses to giant skyscrapers.
This tutorial describes the installation and configuration of Minecraft Server on Ubuntu 18.04. We'll run the Minecraft server using Systemd and connect to the running instance using the mcrcon utility. We will also show you how to create a cronjob that performs a regular server backup.
The same instructions apply to Ubuntu 16.04 and any Ubuntu-based distribution, including Linux Mint and Elementary OS.

prerequisite

Your logged-in user must have sudo permissions to install the package.

Install the packages required for the build tool:mcrcon

sudo apt updatesudo apt install git build-essential

Install the Java runtime environment

Minecraft requires Java 8 or later. Since the Minecraft server does not require a graphical user interface, we will install the headless version of the JRE. This version has fewer dependencies and uses fewer system resources, making it more suitable for server applications.

Install the headless OpenJRE 8 package by running the following command:

sudo apt install openjdk-8-jre-headless

Verify the installation by printing the Java version:

java -version
openjdk version "1.8.0_212"OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)

Create a Minecraft user

For security purposes, Minecraft should not run under the root user. We will create a new system user and group it with the home directory running the Minecraft server:/opt/minecraft

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

We do not set a password for this user. This is a good security practice because the user will not be able to log in via SSH. To change to a user, you need to log in to the server as root or as a user with sudo privileges.minecraft

Install Minecraft on Ubuntu

Before you begin the installation process, make sure to switch to Users.minecraft

sudo su - minecraft

Run the following command to create three new directories within the user's home directory:

mkdir -p ~/{backups,tools,server}
  • backupsThe directory will store your server backups. You can later synchronize the directory to a remote backup server.

  • toolsThe directory stores the client and backup scripts.mcrcon

  • serverThe directory will contain the actual directory. Minecraft servers and their data.

Download and compile mcrcon

RCON is a protocol that allows you to connect to a Minecraft server and execute commands. mcron is a RCON client built into C.

We will download the source code from GitHub and build the binaries.mcrcon

First navigate to the directory and copy the repository from GitHub using the following command:~/toolsTiiffi/mcrcon

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

After cloning is complete, change to the repository directory:

cd ~/tools/mcrcon

Type the following to start compiling the utility:mcrcon

gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c

Once you're done, you can test it by entering:

./mcrcon -h

The output looks like this:

Usage: mcrcon [OPTIONS]... [COMMANDS]...
Sends rcon commands to Minecraft server.

Option:  -h Print usage  -H Server address  -P Port (default is 25575)
  -p Rcon password  -t Interactive terminal mode  -s Silent mode (do not print received packets)
  -c Disable colors  -r Output raw packets (debugging and custom handling)
  -v Output version information

Server address, port and password can be set using following environment variables:
  MCRCON_HOST
  MCRCON_PORT
  MCRCON_PASS

Command-line options will override environment variables.
Rcon commands with arguments must be enclosed in quotes.

Example:
mcrcon -H my.minecraft.server -p password "say Server is restarting!" save-all stop

mcrcon 0.6.1 (built: May 19 2019 23:39:16)Report bugs to tiiffi_at_gmail_dot_com or https://github.com/Tiiffi/mcrcon/issues/

Download Minecraft Server

There are multiple Minecraft server modules, such as Craftbukkit or Spiget, that allow you to add features (plugins) to the server and further customize and adjust server settings. In this guide, we will install the latest Mojang official Minecraft official Minecraft server.

The latest Java archive files (JARs) for Minecraft servers can be downloaded from the Minecraft download page.

At the time of writing, the latest version is . Before proceeding to the next step, you should check if the download page has a new version.1.14.1

Run the following wget command to download the Minecraft jar file to a directory:~/server

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

Configure the Minecraft server

Once the download is complete, you will navigate to the directory and start the Minecraft server:~/server

cd ~/serverjava -Xmx1024M -Xms512M -jar server.jar nogui

When the server is first started, it performs some operations and creates and files and stops.server.propertieseula.txt

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

As you can see from the output above, we need to agree to the Minecraft EULA in order to run the server. Open the file and change to:eula.txteula=falseeula=true

nano ~/server/eula.txt

〜/server/eula.txt

#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).#Sun May 19 23:41:45 PDT 2019eula=true

Close and save the file.

Next, we need to edit the file to enable the RCON protocol and set the RCON password. To open the file using a text editor:server.properties

nano ~/server/server.properties

Locate the following lines and update their values as follows:

〜/server/server.properties

rcon.port=25575rcon.password=strong-password
enable-rcon=true

Don't forget to change to a more secure password. If you don't want to connect to the Minecraft server from a remote location, make sure the rcon port is blocked by a firewall.strong-password

Here you can also adjust the default properties of the server. For more information about possible settings, visit the server.properties page.

Create a Systemd service unit file

To run Minecraft as a service, we will create a new Systemd unit file.

Switch back to your Sudo user by entering.exit

Open your text editor, and then create a file named in :/etc/systemd/system/minecraft.service

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

Paste the following configuration:

/etc/systemd/system/minecraft.service

[Unit]Description=Minecraft ServerAfter=network.target[Service]User=minecraftNice=1KillMode=noneSuccessExitStatus=0 1ProtectHome=trueProtectSystem=fullPrivateDevices=trueNoNewPrivileges=trueWorkingDirectory=/opt/minecraft/serverExecStart=/usr/bin/java -Xmx1024M -Xms512M -jar server.jar noguiExecStop=/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password stop[Install]WantedBy=multi-user.target

Modify and flag according to your server resources. The flag defines the maximum memory allocation pool for the Java Virtual Machine (JVM), while it defines the initial memory allocation pool. Also, make sure to use the correct port and password.XmxXmsXmxXmsrcon

Save and close the file, then reload the systemd manager configuration:

sudo systemctl daemon-reload

You can now start the Minecraft server by doing the following:

sudo systemctl start minecraft

When the service is first started, it generates several configuration files and directories, including the Minecraft world.

Use the following command to check the service status:

sudo systemctl status minecraft
 minecraft.service - Minecraft Server
   Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-05-19 23:49:18 PDT; 9min ago
 Main PID: 11262 (java)
    Tasks: 19 (limit: 2319)
   CGroup: /system.slice/minecraft.service
           `-11262 /usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui

Finally, enable the Minecraft service to start automatically at startup:

sudo systemctl enable minecraft

Adjust the firewall

If your server is protected by a firewall and you want to access your Minecraft server from outside your local network, you need to open port 25565.

To allow traffic on the default Minecraft port, enter the following command:25565

sudo ufw allow 25565/tcp

Configure backups

In this section, we'll create a backup shell script and cronjob to automatically back up the Minecraft server.

To start with switching to a user:minecraft

sudo su - minecraft

Open your text editor and create the following file:

nano /opt/minecraft/tools/backup.sh

Paste the following configuration:

/opt/minecraft/tools/backup.sh

#!/bin/bashfunction 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_%R).tar.gz /opt/minecraft/server
rcon "save-on"## Delete older backupsfind /opt/minecraft/backups/ -type f -mtime +7 -name '
.gz' -delete

Run the following chmod command to save the file and make the script executable:

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

Next, create a cron job that will automatically run once a day at a fixed time.

Open the crontab file by typing:

crontab -e

To run the backup script every day at 23:00, paste the following line:

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

Access the Minecraft console

To access the Minecraft console, you can use utilities. The syntax is as follows, you need to specify the host, rcon port, rcon password and enable terminal mode using the switch:mcrcon-tmcrcon

/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password -t
Logged in. Type "Q" to quit!>

When accessing the Minecraft console from a remote location, make sure that the rcon port is not blocked.

If you regularly connect to the Minecraft console, you don't need to enter this long command and instead create a bash alias.

conclusion

You have successfully installed the Minecraft server on your Ubuntu 18.04 system and set up daily backups.

If you have questions or feedback, please leave a comment below.


Do you have any suggestions for this document?

Your rating for this document
You can earn up to 7% from Cloud server new purchase -renewal (3%)-upgrade (3%) ,simply click on the affiliate application to become a partner.
AboutWorry-free refund guarantee.

Become a Partner vServer Affiliate marketing

All Rights Reserved ©2024. SICloud® IT (HK) LIMITED | Silicon Cloud™ (Tokyo) LLC (電気通信事業者番号 A-05-20586) |