19.8 C
Texas
angeloma
Senior Writer and partner

Install Minecraft Server on Ubuntu 20.04

Hello friends. Minecraft is such a popular and versatile game that we can even install our instance. So in this post, you will learn how to install Minecraft server on Ubuntu 20.04 by following a series of steps.

Minecraft is one of the most acclaimed games that exist today. Its versatility and ability to reinvent itself as well as the fact that no two games are ever the same make it perfect for our free time. It is also very popular among children because of its content.

This game allows us to deploy a server on our computer which makes it quite versatile. And in this post, we will tell you how.

Install Minecraft server on Ubuntu 20.04 – First steps

As expected, Minecraft is not available in the Ubuntu repositories so we will have to download it and configure it manually.

- Advertisement -

To do this, open a terminal or connect via SSH and upgrade Ubuntu

sudo apt update
sudo apt upgrade

Then download the wget and screen packages needed to complete the tutorial. With the wget command we can perform the download via Terminal and with screen we can run this instance.

sudo apt install wget screen

Minecraft is created with Java so we have to install it. To do this just install the default-jdk meta package from the official Ubuntu repositories.

sudo apt install default-jdk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ca-certificates-java default-jdk-headless default-jre default-jre-headless fontconfig-config fonts-dejavu-core java-common libavahi-client3 libavahi-common-data
  libavahi-common3 libcups2 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfontconfig1 libgif7 libgl1 libgl1-mesa-dri libglapi-mesa libglvnd0
  libglx-mesa0 libglx0 libgraphite2-3 libharfbuzz0b libjpeg-turbo8 libjpeg8 liblcms2-2 libllvm11 libnspr4 libnss3 libpciaccess0 libpcsclite1 libsensors-config
  libsensors5 libvulkan1 libx11-6 libx11-data libx11-xcb1 libxau6 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-sync1 libxcb-xfixes0 libxcb1
  libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 libxrender1 libxshmfence1 libxtst6 libxxf86vm1 openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre
  openjdk-11-jre-headless x11-common
Suggested packages:
  cups-common liblcms2-utils pcscd lm-sensors openjdk-11-demo openjdk-11-source visualvm libnss-mdns fonts-dejavu-extra fonts-ipafont-gothic fonts-ipafont-mincho
  fonts-wqy-microhei | fonts-wqy-zenhei fonts-indic
Recommended packages:
  mesa-vulkan-drivers | vulkan-icd libxt-dev libatk-wrapper-java-jni fonts-dejavu-extra
The following NEW packages will be installed:
  ca-certificates-java default-jdk default-jdk-headless default-jre default-jre-headless fontconfig-config fonts-dejavu-core java-common libavahi-client3
  libavahi-common-data libavahi-common3 libcups2 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfontconfig1 libgif7 libgl1 libgl1-mesa-dri
  libglapi-mesa libglvnd0 libglx-mesa0 libglx0 libgraphite2-3 libharfbuzz0b libjpeg-turbo8 libjpeg8 liblcms2-2 libllvm11 libnspr4 libnss3 libpciaccess0 libpcsclite1
  libsensors-config libsensors5 libvulkan1 libx11-6 libx11-data libx11-xcb1 libxau6 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-sync1 libxcb-xfixes0
  libxcb1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 libxrender1 libxshmfence1 libxtst6 libxxf86vm1 openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre
  openjdk-11-jre-headless x11-common
0 upgraded, 62 newly installed, 0 to remove and 38 not upgraded.
Need to get 296 MB of archives.
After this operation, 805 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Download the Minecraft server package

So with this single command, all Java will be installed on the system.

The next step is to create a new user along with a home directory in /opt/minecraft/ to run minecraft. This step, although optional, is highly recommended.

sudo useradd -m -r -d /opt/minecraft minecraft minecraft

And inside the folder we have set for the user, create a folder with the name of the instance. In this case, I have chosen test because it is demonstrative.

sudo mkdir /opt/minecraft/test

Navigate to the instance folder and from there download the server.

cd /opt/minecraft/test
sudo wget -c https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar
--2021-04-10 18:34:16--  https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar
Resolving launcher.mojang.com (launcher.mojang.com)... 65.9.64.20
Connecting to launcher.mojang.com (launcher.mojang.com)|65.9.64.20|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 37962360 (36M) [application/octet-stream]
Saving to: ‘server.jar’

server.jar                                 100%[=====================================================================================>]  36.20M   107MB/s    in 0.3s    

2021-04-10 18:34:17 (107 MB/s) - ‘server.jar’ saved [37962360/37962360]

Note: the download link will change according to the stable version. To do so, visit this link and get the link and modify the command.

Accept the license terms:

sudo bash -c "echo eula=true > /opt/minecraft/test/eula.txt"

Make the instance folder owned by the minecraft user we created.

sudo chown -R minecraft /opt/minecraft/test/

It would be best to handle the instance as a system service, so we need to create a new service file for Minecraft

sudo nano /etc/systemd/system/[email protected]

And add the following content:

[Unit]
Description=Minecraft Server: %i
After=network.target

[Service]
WorkingDirectory=/opt/minecraft/%i

User=minecraft
Group=minecraft

Restart=always

ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx2G -jar server.jar nogui

ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN IN 10 SECONDS. SAVING ALL MAPS... "010'
ExecStop=/bin/sleep 10
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"010'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"010'


[Install]
WantedBy=multi-user.target
1.- Install Minecraft server on Ubuntu 20.04
1.- Install Minecraft server on Ubuntu 20.04

Pay close attention to the ExecStart line because in the -Xmx option is where we will be able to define the amount of RAM we will allocate to the instance. This will depend on the computer. In this case, I have assigned 2Gb.

Then, save the changes and close the editor.

For the system to recognize the new service you have to refresh the service list.

sudo systemctl daemon-reload

Now you can start your instance

sudo systemctl start minecraft@test

And check the status of it:

sudo systemctl status minecraft@test
● [email protected] - Minecraft Server: test
     Loaded: loaded (/etc/systemd/system/[email protected]; disabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-04-10 18:47:06 CEST; 8s ago
   Main PID: 5177 (screen)
      Tasks: 24 (limit: 4566)
     Memory: 417.2M
     CGroup: /system.slice/system-minecraft.slice/[email protected]
             ├─5177 /usr/bin/SCREEN -DmS mc-test /usr/bin/java -Xmx2G -jar server.jar nogui
             └─5178 /usr/bin/java -Xmx2G -jar server.jar nogui

Apr 10 18:47:06 osradar systemd[1]: Started Minecraft Server: test.

To finally check if everything is OK you can monitor port 25565 which is where Minecraft works. To do this you can use the nmap tool.

sudo apt install nmap
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libblas3 liblinear4 liblua5.3-0 lua-lpeg nmap-common
Suggested packages:
  liblinear-tools liblinear-dev ncat ndiff zenmap
The following NEW packages will be installed:
  libblas3 liblinear4 liblua5.3-0 lua-lpeg nmap nmap-common
0 upgraded, 6 newly installed, 0 to remove and 38 not upgraded.
Need to get 5,669 kB of archives.
After this operation, 26.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Then run:

nmap -p 25565 localhost

And you will get an output like this

Starting Nmap 7.80 ( https://nmap.org ) at 2021-04-10 18:50 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00016s latency).

PORT      STATE SERVICE
25565/tcp open  minecraft

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds

This indicates that the instance is running and can be accessed.

Conclusion

Minecraft is a revolution and we can have our instance as easy as that. Thanks to these steps a newbie can have his own server where he can have hours of fun.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article