How To Create A Minecraft Server On Ubuntu 20.04


The author selected the Tech Education Fund to receive a donation as part of the Write for DOnations program.



Introduction



Minecraft is a popular sandbox video game. It was originally released in 2009 and allows players to explore, build, craft, survive, and create a block 3D world. As of late 2019, it was the second best-selling video game of all time. This tutorial will show how to create a Minecraft server that you and your friend can use. You will install the required software packages to run Minecraft and configure the server to run. Finally, you will deploy the game.



Alternately, DigitalOcean''s One Click Minecraft: Java Edition Server is another installation option.



This tutorial uses Java Minecraft. You will not be able to connect to the server if you purchased Minecraft from the Microsoft App Store. Most Minecraft versions purchased on gaming consoles, such as the PlayStation 4 or Xbox One, are also compatible with the Microsoft version. These consoles are not able to connect to this tutorial''s server. You can obtain the Java version of Minecraft here.



Prerequisites



To follow this guide, you will need:



- A server that has Ubuntu 20.04 installed, with a non-root user having sudo privileges and SSH disabled. This guide will help you to set up your server. Minecraft can be resource intensive, so consider this when deciding on the size of your server. DigitalOcean may require more resources. You can always resize Droplets to add more CPUs or RAM.



- Minecraft Java Edition on a local Mac, Windows or Linux.



Step 1 - Install the necessary software packages and configure the firewall



Once you have your server up and running, it''s time to install Java. Java is required to run Minecraft.



Update the package index of the APT package manger:



sudo apt-update Next, install OpenJDK version 16 Java, specifically the headless JRE. This is a minimal Java version without support for GUI applications. This makes it ideal for running Java applications on a server:



sudo apt install openjdk-16-jre-headless You also need to use a software called screen to create detachable server sessions. screen allows you create a terminal session, then detach it from it. The process will continue as normal. MINECRAFT This is important because if your server were to be started and then closed your terminal, it would kill the session. Install screen now



sudo apat install screen


Now that you have the packages installed we need to enable the firewall to allow traffic to come in to our Minecraft server. The initial server setup you did allowed traffic to come in via SSH. You now need to allow traffic to be sent via port 25565, which is the default port Minecraft uses for connections. Run the following command to add firewall rules:



sudo ufw allow 25565


Now that you have Java installed and your firewall properly configured, you will download the Minecraft server from the Minecraft website.



Step 2: Download the Latest Minecraft Version



Now you need to download the current version of the Minecraft server. You can do this by navigating to Minecraft''s Website and copying the link that says Download minecraft_server.X.X.X.jar, where the X''s are the latest version of the server.



You can now use the copied link and wget to download the server.



wget https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar


If you intend to upgrade your Minecraft server, or if you want to run different versions of Minecraft, rename the downloaded server.jar to minecraft_server_1.15.2.jar, matching the highlighted version numbers to whatever version you just downloaded:



mv server.jar minecraft_server_1.15.2.jar


You can find older versions archived at mcversions.net if you wish to download Minecraft. This tutorial will concentrate on the current version. Now that you have your download let''s start configuring your Minecraft server.



Step 3 - Configuring and Running the Minecraft Server



Now that you have the Minecraft jar downloaded, you are ready to run it.



First, open a screen session using the screen command.



Screen


After you have read the banner, press the SPACE button. This will open a terminal session, just as usual. This session can now be detached, so you can start a command and then leave it running.



You can now perform your initial configuration. Don''t be alarmed if the next command throws an Error. Minecraft''s installation is designed so that users have to agree to the company licensing agreement. You will do this next.



1. java -Xms1024M -Xmx1024M -jar minecraft_server_1.15.2.jar nogui


Before we examine the output of this command, let''s take a closer glance at all the command line arguments, which are tuning you server.



- Xms1024M: This tells the server to start with 1024MB of RAM or 1GB. This limit can be increased if you need more RAM. You have two options: M for megabytes andG for gigabytes. For example, Xms2G will launch the server with 2 gigabytes RAM.



- Xmx1024M: This tells the server that it can only use 1024M of RAM. You can raise this limit if you want your server to run at a larger size, allow for more players, or if you feel that your server is running slowly.



- jar – This flag specifies which server''s jar file to run.



- Nogui - This tells server not to launch a GUI as this is a client.



This command normally starts your server. It will generate the following error instead.



These errors were generated because the server could not find two necessary files required for execution: the EULA (End User License Agreement), found in eula.txt, and the configuration file server.properties. Fortunately, since the server was unable to find these files, it created them in your current working directory.



First, open the eula.txt file in nano or another text editor.



nano eula.txt


You will find a link in this file to the Minecraft EULA. Copy the URL:



Open the URL in your browser and read the agreement. Then return to your text editor and find the last line in eula.txt. You will need to change eula=false from eula=true. Now save and close the file.



Now that you have accepted the EULA it is time for you to configure the server according to your specifications.



The new server.properties file will be located in your current working folder. This file contains all of the configuration options for your Minecraft server. You can find a detailed list of all server properties on the Official Minecraft Wiki. You will modify this file with your preferred settings before starting your server. This tutorial will cover the fundamental properties:



nano server.properties


The following image will be displayed on your file:



Let''s have a closer look at some the most important properties included in this list.



- difficulty (default easy) - This sets the difficulty of the game, such as how much damage is dealt and how the elements affect your player. There are four choices: easy, normal and hard.



- gamemode (default survival) - This sets the gameplay mode. The options are survival, creative,adventure, and spectator.



- level–name (default realm) - This defines the name of your server and will be displayed in the client. Characters such as an apostrophe might need to be escape with a backslash.



- motd (default A Minecraft Server) - The message that is displayed in the server list of the Minecraft client.



- pvp (default true) - Enables Player versus Player combat. If true, players can engage in combat with each other and cause damage.



After you have selected the options you wish, save the file and close it.



You can now start your server successfully after you have changed the EULA to true.



Let''s start our server with 1024M RAM, just like last time. Let''s give Minecraft access up to 4G of RAM. This number can be adjusted to meet your server''s limitations or user''s needs.



1. java -Xms1024M -Xmx4G -jar minecraft_server_1.15.2.jar nogui


Give the initialization a moment. Soon your new Minecraft server will start producing an output similar to this:



Once the server has been up and running, the following output will be displayed:



Now your server is running and you have been redirected to the server administrator control panel. Now type help.



help


This output will be available:



From this terminal you can execute administrator commands and control your Minecraft server. Now let''s use screen to keep your new server running, even after you log out. Next, you can connect to Minecraft and start a new Minecraft server.



Step 4 – Keeping the server running



Once your server is set up, you want the server to continue running even if you disconnect from your SSH session. You can detach from this session using screen as a shortcut. Press Ctrl +A + D to return to your original shell.


This command will display all screen sessions.



screen –list You''ll receive an output with the session ID, which you will need to resume that session.



To resume your session, pass -r to the screen command. Next, enter your session ID.



screen –r 26653 Be sure to detach the session from your server with Ctrl+A + D before you log out.



Step 5 - Connecting to the Minecraft Server from the Minecraft Client



Now that your server is up and running, let''s connect to it through the Minecraft client. Now you can start playing!



Launch your copy of Minecraft Java Edition and select Multiplayer in the menu.



Next, you will need to add a server to connect to, so click on the Add Server button.



In the Edit Server Info screen, give your server an address and type in your IP address. This is the exact IP address that was used to connect through SSH.



Once you have entered your server name and IP address, you''ll be taken back to the Multiplayer screen where your server will now be listed.



This list will continue to show your server''s name. Select it and click Join Server.



You are now in your server and ready for play!



You now have a Minecraft server running on Ubuntu 20.04 for you and all of your friends to play on! Enjoy exploring, crafting, and surviving within a primitive 3D world. Remember to be careful of griefers.