This is a tutorial that I wrote on my previous blog and I thought I would re-write it for this one.
Minecraft is a popular sandbox game that has been around since 2009. It’s constantly been updated over the years and the game today hardly resembles the original.
Because of this, it has continued to grow in popularity and its multiplayer feature has allowed friends to play and build together on a shared server.
This tutorial will show you how to install a Minecraft Server on an Ubuntu 18.04 server.
The Minecraft Server is a Java Application provided for free by Mojang. The first thing we need to install is OpenJDK.
sudo apt install -y openjdk-8-jdk-headless
Once complete you can confirm it was installed correctly.
The Minecraft Server is going to create some files when it runs so it’s best to create a directory for it to run. I’m going to run it from a directory in my home directory.
mkdir ~/minecraft-server cd ~/minecraft-server
Now that we have Java installed we need to download the Minecraft Server binary. You can use the command below which at the time of writing is version 1.15.2. To get the latest version go to the Minecraft Server Download page, copy the link and replace the one in the command below.
We are almost ready to run our Minecraft Server for the first time but first, we need to create an End User License Agreement file or the server will refuse to start.
echo "eula=true" > eula.txt
Let’s test our server for the first time. On the first run, it will generate the world and various other one-time setups it needs to run. Depending on the specification of your server this might take a few minutes.
java -Xms512m -Xmx1G -jar server.jar
The command above has a couple of options associated so let see what it’s doing.
- -Xms512m: Tells Java to start with 512Mb of RAM.
- -Xmx1G: Tells Java it can’t use more than 1Gb of RAM.
Once the server has finished starting you will be able to connect to it from your Minecraft Client. Just remember to open the port 25565 so the client can connect.
We now have our Minecraft Server up and running and as you can see it was very easy. Installing in on a server in the real world would need a little more security and we can add some quality of life changes too.
On the terminal, you will notice that we are tied to the Minecraft Console. This is actually the Admin console and we can type Minecraft commands into it.
time set day give <player_name> diamond 64
This is pretty cool but there is a problem. We are tied to that console which means if we try to logout the server will shut down and unless we want the console open forever we should fix it.
Run Minecraft Server with Screen
To get around this we are going to use a program called screen. Press Ctrl+C to stop the server and lets use screen to start Minecraft. If you are using the install from my VirtualBox Tutorial screen is installed by default so we don’t need to install any more packages.
screen java -Xms512m -Xmx1G -jar server.jar
You will see the server startup exactly as it did before except this time we are running within a screen session.
If you now hit
Ctrl+A and then hit
d you will be detached from the screen session and the server will continue to run in the background. This means that we can do other things, including log out and our Server will keep running.
If we want to reattach to run more command (Give ourselves more diamonds) we can run the following to get a list of screen sessions currently running:
screen -ls There is a screen on: 3241.minecraft (03/03/2020 02:31:11 PM) (Detached) 1 Socket in /run/screen/S-dbarszczak.
Then we can re-attach to the console with:
screen -r minecraft
Run Minecraft Server as a Service
At this stage, we have a Minecraft server that we can start and stop and we can put into the background. We can reattach anytime we want too so the last thing we need to do it to get it to run as a Service. This will make it very easy to start and stop. It will also start when the server is rebooted.
Note: This part is specific for Ubuntu 18.04 as it uses Systemd. Your OS might use Systemd but the files may not be in the same places.
We need to create a Service File for Systemd.
sudo vim /lib/systemd/system/minecraft-server.service
Add the following to that file and then save and quit. Don’t forget to change the username in the WorkingDirectory, User & Group.
[Unit] Description=Simple Minecraft Server [Service] WorkingDirectory=/home/dbarszczak/minecraft-server User=dbarszczak Group=dbarszczak Type=forking ExecStart=/usr/bin/screen -dmS minecraft /usr/bin/java -Xms512M -Xmx1G -jar server.jar nogui [Install] WantedBy=multi-user.target
Starting and stopping our service now becomes more standard:
sudo systemctl start minecraft-server.service # Start Server sudo systemctl status minecraft-server.service # Get the status sudo systemctl stop minecraft-server.service . # Stop Server
As well as commands that are a lot easier to remember the Minecraft Server will start if the server is rebooted. Accessing the console is exactly as it was before.
screen -ls screen -r minecraft
Setting up and Minecraft Server is very easy as you can see. It could be done by installing Java, downloading a file and then running it. It gets a little more complicated as you can see when we wanted to run it so we could log out of the server. Then a little more when we wanted to use Systemd. Even then though it’s not particularly difficult.
Before you try and install this on the internet somewhere you should keep a couple of things in mind with this installation.
- This is for testing or local servers.
- It’s running the Minecraft default so anyone could log in.
- It doesn’t have any DDOS Protection.
- It should really run as a Minecraft user.
I hope that you learned something from this Walkthrough and if you would like me to do a tutorial on setting up a production Minecraft Server let me know in the comments.