How To Create A Minecraft Server On Ubuntu 20.04

· 7 min read
How To Create A Minecraft Server On Ubuntu 20.04


The Tech Education Fund was the recipient of a donation from Write for DOnations.



Introduction



 Minecraft is a popular sandbox video game. Originally released in 2009, it allows players to build, explore, craft, and survive in a block 3D generated world. It was the second-best-selling videogame of all time as of late 2019. This tutorial will show how to create a Minecraft server that you and your friend can use. In this tutorial, you will install the necessary software to run Minecraft, configure it to run, then deploy the game.



 Alternately, you can explore DigitalOcean's One-Click Minecraft: Java Edition Server as another installation path.



This tutorial uses Java Minecraft. If you purchased your version of Minecraft through the Microsoft App Store, you will be unable to connect to this server. The Microsoft version of Minecraft is also available for most Minecraft versions purchased on gaming consoles like the PlayStation 4, Xbox One or Nintendo Switch. These consoles are also unable to connect to the server built in this tutorial. You can download the Java version here.



Prerequisites



You will need the following items to follow this guide:



- A server with Ubuntu 20.04 installed. This guide will help you to set up your server. Minecraft can be resource-intensive, so keep that in mind when selecting your server size. DigitalOcean allows you to resize your Droplet to increase CPUs and RAM.



- Minecraft Java Edition installed on a local Mac or Windows machine.



Step 1 – Installing the necessary software packages, and configuring the firewall



Once your server is up and running, you can install Java. This is essential for Minecraft to run.



Update the package index of the APT package manger:



 sudo apt update Next, install the OpenJDK version 16 of Java, specifically the headless JRE. This is a minimal Java version that does not support 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 to create a terminal session and detach from it, leaving the process started on it running. 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 apt 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. In the initial server setup that you performed you only allowed traffic from SSH. You must now allow traffic to port 25565 to access Minecraft. Add the necessary firewall rule by running the following command:



 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.



To download the server, you will need to use wget with the copied link



 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. But this tutorial will focus on the current latest release. 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.



Start a screen session by running this screen command:



 screen


After you have read the banner, press the SPACE button. screen will present you with a terminal session like normal. This session is now detachable, which means that you'll be able to start a command here and leave it running.



Now you can execute your initial configuration. If the next command throws errors, don't panic. Minecraft's installation was designed in a way that users must consent to the company’s licensing agreement.  Roof Info This is what you will do next:



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


Let's first examine the output of this command. Next, let's look at all the command-line arguments that are tuning your server.



- Xms1024M: This tells the server to start with 1024MB of RAM or 1GB. You can raise this limit if you want your server to start with more RAM. You can choose between M for megabytes or G for gigabytes. For example, Xms2G will launch the server with 2 gigabytes RAM.



- Xmx1024M This allows the server to use a maximum of 1024M RAM. If you wish your server to run at higher speeds, allow for more players, and if your server is running slow, you can increase this limit.



- 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 will not normally start your server the first time it is run. Instead, it will produce the following error



These errors were caused by the server not finding two files necessary for execution: the EULA (End User License Agreement), located in eula.txt and the configuration fileserver.properties. These errors were caused by the server not being able to locate the files. It created them in your current work directory.



Open eula.txt first in nano or any other text editor.



 nano eula.txt


This file contains a link to the Minecraft EULA. Copy the URL.



Open the URL in a web browser and go through the agreement. Next, return to your text editor. Find the last line of eula.txt. You will need to change eula=false from eula=true. Now save and close the file.



Now that you have accepted and confirmed the EULA, it's time to configure your server to your specifications.



 In your current working directory, you will also find the newly created server.properties file. This file contains all of the configuration options for your Minecraft server. You can find a complete list on the Official Minecraft Wiki of all server property information. This file can be modified with your preferred settings, before you start your server. This tutorial will discuss the fundamental properties.



 nano server.properties


This is how your file will look like:



Let's take an in-depth look at the most important properties on this list.



- difficulty (default: easy) - This controls the difficulty of the game. It determines how much damage is dealt to your player and how the elements affect them. There are four options available: peaceful, easy, normal, or hard.



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



 - level-name (default world) - This sets the name of your server that will appear 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 will have the ability to damage and engage in combat.



After you've set the options you want, save the file.



Now that you have set the EULA to true as well as your settings, you are ready to start your server.



 Like last time, let's start your server with 1024M of RAM. Let's give Minecraft access up to 4G of RAM. Remember, you are welcome to adjust this number to fit your server limitations or user needs:



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


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



 Once the server is up and running, you will see the following output:



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 see screen to continue your 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



Now that your server is up, you want it continue to run even after you disconnect from SSH. Since you used screen earlier, you can detach from this session by pressing Ctrl + A + D. Now you're back in your original shell.


 Run this command to see all of your 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 the –r flag to the screen command. After that, enter your sessionID:



 screen -r 26653  When you are ready to log out of your server, be sure to detach from the session with Ctrl + A + D and then 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.



The Edit Server Info screen will open. Give your server a name and enter the IP address of the server. This is the exact IP address that was used to connect through SSH.



Once you've entered your server name or IP address, you'll return to the Multiplayer screen. Here your server will be listed.



 From now on, your server will always appear in this list. Select it, and then click Join Server.



 You are in your server and ready to play!



 You now have a Minecraft server running on Ubuntu 20.04 for you and all of your friends to play on! Have fun exploring, crafting and surviving in a 3D world. Beware of griefers.