How To Create A Minecraft Server On Ubuntu 2004

From Human's Love
Jump to: navigation, search

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 first released in 2009. It allows players to create, explore, craft and survive in a block-generated 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. In this tutorial, you will install the necessary software to run Minecraft, configure it to run, then deploy the game.



Alternately there is DigitalOcean’s One Click Minecraft: Java Edition Server.



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 will not connect to the server that was built in this tutorial. You can download the Java version here.



Prerequisites



You will need the following items to follow this guide:



- A server that has Ubuntu 20.04 installed, with a non-root user having sudo privileges and SSH disabled. To initialize your server, follow this guide. Minecraft can be resource intensive, so consider this when deciding on the size of your server. DigitalOcean allows you to resize your Droplet to increase CPUs and RAM.



- A copy of Minecraft Java Edition installed on a local Mac, Windows, or Linux machine.



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



After your server is initialized, the next step is to install Java. It's necessary to run Minecraft.



Update the package index to the APT Package Manager:



sudo update Next, download the OpenJDK Version 16 of Java. This includes the headless JRE. This is a minimal Java release that does not support GUI apps. This makes it ideal for running Java apps 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 and then detach from it. This will allow you to continue the process. 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. 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. 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.



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. 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 first by running the screen command



Screen Once you have read the banner that has appeared, press the SPACE bar. You will see a terminal session as normal. This session is now removable, which means you can launch a command from here and then quit it.



Now you can start your initial configuration. If the next command throws errors, don't panic. Minecraft's installation is designed so that users have to agree to the company licensing agreement. This is what you will do next:



1. java -Xms1024M -Xmx1024M -jar minecraft_server_1.15.2.jar nogui Before examining this command's output, let's take a closer look at all these command-line arguments, which are tuning your server:



- Xms1024M: This tells the server to start with 1024MB of RAM 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 will start the server with 2 gigabytes of RAM.



- Xmx1024M - This configures the server to use, at most, 1024M of RAM. This limit can be increased if your server needs to run at a larger scale, allow more players, or if your server is slow.



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



- nogui: This tells a server not to launch any GUI since it is a server.



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 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. These errors were caused by the server not being able to locate the files. It created them in your current work directory.



First, open eula.txt in 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 browser and read the agreement. Then return to your text editor and find the last line in eula.txt. This will change eula=false into eula=true. Save the file and close it.



Now that you've accepted the EULA, it is time to configure the 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. On the Official Minecraft Wiki, you can find a detailed listing of all server properties. 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 This is how your file will look like:



Let's take a closer look at some of the most important properties in this list:



- 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 available: peaceful, easy, normal, or hard. MINECRAFT



- gamemode (default survival) - This sets the gameplay mode. There are three options: survival; creative; adventure; and spectator.



- level-name (default universe) - This is the name of the server that 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'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. We can also give Minecraft access to up to 4G RAM, if Minecraft needs it. 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 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:



Your server is now running, and you have been dropped into the server administrator control panel. Now type help:



Help An output like this will appear:



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 you have set up your server, you want it running even after you disconnect. Since you used screen earlier, you can detach from this session by pressing Ctrl + A + D. Now you're back in your original shell.



To see all of your screen sessions, run this command:



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 Once you are ready to log off of your server, make sure to disconnect from the session by pressing Ctrl+ A + D. Then log off.



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. 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.



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've entered your server name or IP address, you'll return to the Multiplayer screen. Here your server will be listed.



Your server will now always be listed in this list. MINECRAFT Select it and 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.