Minecraft is one of the most popular sandbox video game developed by Swedish game developer Markus Person and is now owned by Microsoft. It is a multiplayer game and is available on a wide range of platforms.
A game titled Minecraft: Story Mode was at rage around the world and had around 91 million active players monthly. More and more Minecraft players are now choosing to host their own Minecraft server and play with their counterparts from all over the world.
This tutorial covers the installation of Minecraft server in an Ubuntu 18.04 Server that is hosted in the cloud.
If you don’t want to get in-depth of all these tech stuff and all you want is to enjoy playing the Minecraft with your friends online then buy a dedicated or shared hosting and host your Minecraft game there, head over to this post where we discussed and review top 10 minecraft server hosts.
Prerequisites
- You can SSH into the Ubuntu 18.04 system using root or sudo enabled user
- For better experiences with playing Minecraft games with multiplayer options, it is recommended to have at least 2GB of RAM in the Ubuntu 18.04 system
Creating Ubuntu 18.04 as a Minecraft Server
Prerequisites for installing Minecraft on Ubuntu
1. Install JAVA
Minecraft is written in java and hence to run it in your server you need to install JRE 8 or greater beforehand. Run the following command in the terminal to install latest JRE in an Ubuntu 18.04 system.
# apt install openjdk-11-jre-headless
Check the version of installed JRE by using following command:
# java -version
2. Install few development tools
Also install the following tools those will be needed at various stages of installing and configuring Minecraft.
# apt install gcc make git wget
3. Add Minecraft user
It is always a good idea to run a minecraft server by using a non root user from security point of view. Run the following command in the terminal to create a new user with a home directory /home/minecraft and without any password.
# useradd -r -m -d /home/minecraft -s /bin/bash minecraft
To navigate to the shell of minecraft user, you need to log in to the system using either root or sudo enabled user.
4. Setting up the Server
Although Minecraft server can be installed and run from a single directory but for better maintenance of Minecraft server we will segregate few functionalities of it like creating a backup location, a folder for RCON client and above all a folder for Minecraft server.
To do that, run the following command from the terminal to create folders for said functionalities.
# su - minecraft # mkdir ~/{backup,tools,server}
5. Install mcrcon
Mcrcon is IPv6 compliant RCON(Remote Console) client well suited for remote administration of minecraft server such as the map, gravity, setting number of players and more through console commands.
You can skip this step if you are not planning to administer a Minecraft server.
Download mcrcon from github followed by compiling and installing it by using root or sudo enabled user and once done change the ownership of mcrcon script to the minecraft user.
# cd /home/minecraft/tools # git clone https://github.com/Tiiffi/mcrcon.git # cd mcrcon # make # chown minecraft:minecraft mcrcon
Usages of mcrcon
mcrcon [OPTIONS]... [COMMANDS]...
Where the options can be any one of the following:
- -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
We will use the mcrcon tool during the process of configuring the systemd script for minecraft server at a later stage.
6. Download & Install Minecraft
Download the latest minecraft server to the folder(~/server) that we have created previously especially for running the minecraft server.
# su - minecraft # cd server # wget https://launcher.mojang.com/v1/objects/d0d0fe2b1dc6ab4c65554cb734270872b72dadd6/server.jar
Once the download is complete, run the JAR file by using the following command.
During the first run minecraft server will run a few tasks and will create server.properties and eula.txt files and exits. The server.properties file stores all the settings for a multiplayer.
# java -Xmx1024M -Xms512M -jar server.jar nogui [06:49:28] [main/ERROR]: Failed to load properties from file: server.properties [06:49:28] [main/WARN]: Failed to load eula.txt [06:49:28] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
Now you need to accept the license in eula.txt. You can do that by adding “eula=true” in the file with the following command:
# sed -i.orig 's/eula=false/eula=true/g' eula.txt
Proceed with enabling rcon protocol in your Minecraft server. To do that edit the server.properties file and update the values for the following parameters. Keep other the values for other parameters as it is for the time being.
You can adjust those parameters at a later stage by consulting the documentation from here.
# su - minecraft # cd /home/minecraft/server # vi server.properties ... ... rcon.port=25575 rcon.password=Passw0rd! enable-rcon=true ... ...
7. Create systemd daemon file
At this moment, Minecraft server is installed in your system. For better management of minecraft server like starting and stopping of minecraft server, create a systemd daemon file.
To do that navigate to the systemd directory and create a systemd service file using your favorite text editor.
# cd /etc/systemd/system # vi minecraft.service [Install] WantedBy=multi-user.target [Unit] Description=Start Minecraft After=network.target [Service] Type=simple User=minecraft Group=minecraft ExecStart=/home/minecraft/server/start_minecraft_server.bash ExecStop=/home/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p Passw0rd! stop TimeoutStartSec=0 [Install] WantedBy=default.target
Make the above systemd script executable.
# chmod +x /etc/systemd/system/minecraft.service
Next create a shell script to run/execute the minecraft jar file (server.jar) to start the minecraft server. This shell script is configured in the above systemd daemon file to start minecraft server during system boot.
To do that, change to the minecraft server folder and create a shell script with your favorite text editor.
# cd /home/minecraft/server # vi start_minecraft_server.bash #!/bin/bash cd /home/minecraft/server exec java -Xmx1024M -Xms512M -jar server.jar nogui
Make the above shell script executable and change the ownership of all the folders those we have created previously to minecraft user.
# chown u+x /home/minecraft/server/start_minecraft_server.bash # cd /home/minecraft # chown -R minecraft:minecraft *
Before starting minecraft server using systemd daemon file, make sure that minecraft server can be started with the above shell script. To do that, change to the shell of minecraft user and run it.
# su - minecraft # cd server # ./start_minecraft_server.bash ... ... [15:09:47] [Server thread/INFO]: Preparing spawn area: 90% [15:09:48] [Server thread/INFO]: Preparing spawn area: 93% [15:09:48] [Server thread/INFO]: Preparing spawn area: 93% [15:09:49] [Server thread/INFO]: Time elapsed: 26035 ms [15:09:49] [Server thread/INFO]: Done (83.952s)! For help, type "help" [15:09:49] [Server thread/INFO]: Starting remote control listener [15:09:49] [RCON Listener #1/INFO]: RCON running on 0.0.0.0:25575
Once minecraft server is running, find if the mcrcon can reach the minecraft server by executing the following commands from another terminal:
# su - minecraft # cd tools/mcrcon # ./mcrcon -H localhost -P 25575 -p Passw0rd! -t Logged in. Type "Q" to quit!
If everything goes correctly, you can now start/stop minecraft server using systemd daemon script. Press CTRL+C to stop the minecraft server and start it again with systemd script:
# systemctl start minecraft.service # systemctl status minecraft.service # systemctl stop minecraft.service
8. Backup Minecraft server
Once minecraft server is up and running then you need to take a regular backup of minecraft server world so that you can restore the world from the backup if there is some unwanted changes to it.
In this section we will download and configure a freely available backup script for a minecraft server.
To start with, navigate to the backup folder to download the script and make it executable.
# su - minecraft # cd backup # wget https://raw.githubusercontent.com/nicolaschan/minecraft-backup/master/backup.sh # chmod u+x backup.sh
Now from backup folder execute the above script by specifying the server world path and backup location. But before that create a folder based on current date where the backup will be saved.
# now=$(date +"%T_%d_%m") # mkdir $now # ./backup.sh -c -i /home/minecraft/server/world -o /home/minecraft/backup/$now
The script will warn about minecraft server screen name being not specified. Ignore the warning and find the zipped backup file in the configured folder.
# ls -l /home/minecraft/backup/07:42:16_20_07 total 3228 -rw-rw-r-- 1 minecraft minecraft 3301599 Jul 20 07:42 2019-07-20_07-42-58.tar.gz
Adjust the leaf folder name in the backup path as per yours. Mine being created by the name 07:42:16_20_07.
9. Adjust firewall
To allow access to minecraft server from anywhere open the minecraft port 25565 to the outside world using following command. This step is needed if you have already enabled the UFW firewall in your server.
# ufw allow 25565/tcp # ufw reload
If you want to go in simple route, just hit few simple clicks and your minecraft game server is ready, then simply buy minecraft hosting from experts and start playing the game.
If you followed the above steps without getting any error messages, you are well to go and play the minecraft on your newly setup and hosted minecraft server.
If you face any difficulties while following the above mentioned steps, let us know by dropping a comment below and we are more than happy to assists to setup your own minecraft server.
If you have any feedback, comments or anything please leave us comment below.