How To Create A Minecraft Server On Ubuntu 2004

From Mozilla Foundation
Jump to: navigation, search

The Tech Education Fund was chosen by the author as a recipient of a donation in the Write for DOnations program.



Introduction



Minecraft is a well-known sandbox videogame. It was originally released in 2009 and allows players to explore, build, craft, survive, and create a block 3D world. It was the second most popular video game in late 2019 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 you can also explore DigitalOcean’s One-Click Minecraft Java Edition Server as an alternative installation path.



This tutorial uses the Java version of Minecraft. If you purchased your version of Minecraft through the Microsoft App Store, you will be unable to connect to this server. Most Minecraft versions purchased on gaming consoles, such as the PlayStation 4 or Xbox One, are also compatible with the Microsoft version. These consoles cannot connect to the server created in this tutorial. The Java version can be found here.



Prerequisites



This guide will be followed if you have:



- A server with a fresh installation of Ubuntu 20.04, a non-root user with sudo privileges, and SSH enabled. To initialize your server, follow this guide. Minecraft can be resource-intensive. Keep this in mind when you select your server size. If you are using DigitalOcean and need more resources, you can always resize your Droplet to add more CPUs and RAM.



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



Step 1 - Installing 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 the OpenJDK version 16 of Java, specifically the headless JRE. This is a minimal Java release that does not support GUI apps. This makes it perfect for running Java applications on servers.



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 as if you start your server and then close the terminal, it will kill the session and terminate your server. 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. Now you need to allow for traffic to come in via port 25565, which is the default port that Minecraft uses to allow connections. 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 - Downloading 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. 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 reading the banner, press and hold the SPACE key. screen will present you with a terminal session like normal. This session is now detached, which means you can start a new command here and let it run.



Now you can execute your initial configuration. Don't be alarmed if the next command throws an Error. Minecraft has designed its installation this way so that users must first consent to the company's licensing agreement. 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 allows the server's RAM to be set up to either 1024MB, or 1GB. You can increase this limit if your server needs more RAM. You have two options: M for megabytes andG for gigabytes. For example, Xms2G starts the server with 2 gigabytes (RAM).



- Xmx1024M - This configures the server to use, at most, 1024M of RAM. This limit can be raised if you wish to allow more players or if the server is slow.



- 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 generated by the server failing to find the two required files for execution: the EULA, End User License Agreement, found in eula.txt. and the configuration.properties. The server couldn't find these files so it created them in the current working directory.



First, open eula.txt using nano or your favorite text editor.



nano eula.txt You will find a link within this file to the Minecraft EULA. Copy the URL:



Open the URL in your web browser and read the agreement. Return to your text editor, and then find the last line in "eula.txt". This will change eula=false into 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 complete list on the Official Minecraft Wiki of all server property information. Before you can start your server, you will need to modify this file. This tutorial will focus on the most important properties.



nano server.properties Your file will appear like this:



Let's take a closer view at some of these most important properties:



- difficulty (default is easy) – This determines the difficulty of a game, such how much damage you are dealt and how the elements impact your player. There are four options: normal, peaceful, hard, normal, and easy.



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



- level_name (default world), - This determines the name of your server, which will be displayed in 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 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. You are free to adjust this number to suit your server limitations or user requirements.



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 has been up and running, the following output will be displayed:



You have been dropped into the server administrator panel. Your server is now up and running. Now, type help.



help This output will be available:



From this terminal you can execute administrator commands and control your Minecraft server. Let's now use screen to continue the operation of your server even after you log off. 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.



Run this command to see all of your screen sessions:



screen -list You'll get an output with the ID of your session, which you'll 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 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



Let's connect to your server now that it is up and running. You can then play!



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



Next, you'll need to add a new server to connect to. Click on "Add Server" to proceed.



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



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



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



You are now in control of your server and are 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 crude 3D world. Beware of griefers.