How to install a Minecraft server on Ubuntu linux server

Annonse 1

Annonse 1

In this tutorial, you will learn how to set up a Minecraft server on Ubuntu.

Prerequisites

  • Access to a command line/terminal
  • An Ubuntu server
  • At least 5GB of RAM
  • Intel core-based CPUs or AMD K8-based CPUs IBM 970 2.0 GHz
    and better

Setting up a Minecraft Server

Step 1: Connect to Your Via SSH or use local ROXTerm

The first step is to connect to your server.

1. Open the SSH terminal on your local machine and run the following command:

ssh your_username@host_ip_address

2. Type in your password and hit Enter.

If you are connecting to the server for the first time, you need to confirm you want to continue connecting. Type yes and hit Enter.

You should now be connected to your dedicated server.

Alternativ, use ROXTerm on the Ubuntu server direct

Step 2: Install Java

Once you are connected to the server, move on to installing Java.

We are going to set up the Java Development Kit (Open JDK), an open-source implementation of the Java platform.

The installation steps differ slightly depending on the Linux distribution running on your server.

Install Java on Ubuntu

1. Update the repository to ensure you download the latest version of OpenJDK:

sudo apt update

2. Then, run the command to install the latest Java Development Kit:

sudo apt install default-jdk -y

3. Confirm the installation by typing y (yes) and press Enter.

4. Verify Java is installed on your Ubuntu server by running:

java -version

The output should respond with the version of OpenJDK installed on the system.

If you have an older version of java, eg 8, that you want to remove, use this command:

sudo apt-get autoremove openjdk-8-jdk

Step 3: Install Screen

Screen is a console application that keeps your server running when you’re not connected.

  • Install Screen on Ubuntu with:
sudo apt install screen -y

Step 4: Create a Directory for Minecraft Files

1. Create a minecraft directory where you will store the Minecraft files:

mkdir /home/minecraft-server

2. Then, move into the new directory with:

cd /home/minecraft-server

Step 5: Download the Required Configuration Files

1. Navigate to the Minecraft download page, right-click on the minecraft-server release and copy the link location. (Ctr-Alt-C)

2. Next, download the Minecraft server files using the wget command. Paste the link location copied in the previous step (Ctrl-Alt-V):

wget https://launcher.mojang.com/v1/objects/35139deedbd5182953cf1caa23835da59ca3d7cd/server.jar (this is sample link. You need to use the copied link from webpage)

The output informs you it has downloaded the Minecraft server files and saved them under the name server.jar.

3. Rename the server.jar file so it matches the name of the Minecraft edition downloaded. At the time of writing, the latest Minecraft server release is 1.19. Therefore, we used the following command to rename the server.jar file into minecraft_server.1.19.jar:

mv server.jar minecraft_server.1.19.jar

4. Next, execute the following command:

java -Xms1024M -Xmx2048M -jar minecraft_server.1.19.jar nogui

The output responds with an error informing you that you need to agree with the EULA (End User License Agreement) to run the service. Move on to the next step to do so.

NOTE! If you get this error message:

Error: LinkageError occurred while loading main class net.minecraft/bundler/Main has been compiled by a more recent version of the Java Runtime …..

then you need to download a developer version of Java, execute the following command

sudo apt-get update

For our installation, we had to install version 17

sudo apt install openjdk-17-jdk -y

Then try previous 4. under step 5 once more.

java -Xms1024M -Xmx2048M -jar minecraft_server.1.19.jar nogui

Step 6: Accept Minecraft’s EULA

1. List the contents of the /minecraft directory to verify you have the eula.txt file:

ls

2. Open the EULA file with a text editor of your choice, we use nano:

nano eula.txt

3. The file contains a URL that takes you to the Minecraft end user license agreement. Navigate to the web page and read through the license agreement.

4. If you agree with the terms, return to the terminal window and modify the eula.txt file. Change the line eula=false into eula=true.

5. Save the changes (CTRL+O) and exit the text editor (CTRL+X).

Step 7: Run Screen

Start a Screen session using the screen command and add the -S option to name the session:

screen -S "Minecraft server"

Step 8: Run Your Minecraft Server

1. Try starting the Minecraft server again by rerunning the java command to executing the jar file:

java -Xms1024M -Xmx2048M -jar minecraft_server.1.19.jar nogui

Wait for the system to finish executing. You should get a message that the process is Done!, meaning that the Minecraft server is up and running.

2. You can now detach from the Minecraft screen by pressing Ctrl+a+d.

3. To reattach to the screen, press Ctrl+r.

Note: To make changes to the default configuration, refer to the server.properties file stored in the ——- /home/minecraft-server directory.

Step 9: Configure Firewall

To allow incoming connections from Minecraft, you need to edit the firewall configuration. By default, Minecraft uses port 25565.

The following command enables port forwarding for ufw:

sudo ufw allow 25565

(Rest is optional – not tested)

Step 10 A: Simple startup-script

(Testet but didn’t work. Any idea for solution?)

Prerequisites
Set up a user and group for minecraft so that it doesn’t run as root

sudo adduser –system –home /minecraft-server minecraft

sudo addgroup –system minecraft

adds user «minecraft» to the group «minecraft»

sudo adduser minecraft minecraft

Hand your server-installation over to your new user

sudo chown -R minecraft.minecraft /home/minecraft-server

After creating user and group :

sudo nano /lib/systemd/system/minecraft-server.service

inside :

[Unit]
Description=start and stop the minecraft-server
[Service]
WorkingDirectory=/home/minecraft-server
User=minecraft
Group=minecraft
Restart=on-failure
RestartSec=20 5
ExecStart=/home/minecraft-server/java -Xms1024M -Xmx2048M -jar minecraft_server.1.19.jar –nogui
[Install]
WantedBy=multi-user.target

To enable the service :

sudo systemctl enable minecraft-server.service

To start the service:

sudo systemctl start minecraft-server.service

View the status («q» to go out of the view):

systemctl status minecraft-server.service

If you would like to interact with the server from your keyboard, you may use an alternative service configuration like this:

(Testet but didn’t work. Any idea for solution?)

[Unit]
Description=minecraft-server
[Service]
WorkingDirectory=/home/minecraft-server
User=minecraft
Group=minecraft
Type=forking
ExecStart=/home/minecraft-server/screen -dmS minecraft /home/minecraft-server/java -Xms1024M -Xmx2048M -jar minecraft_server.1.19.jar –nogui
[Install]
WantedBy=multi-user.target


If you have changed the service file, you should issue the

systemctl daemon-reload

and maybe also

systemctl restart minecraft-server.service

command in order to update the system.

If you get an error, try executing

systemctl status minecraft-server.service

and

journalctl -xe

for details.

You can stop server by using the command

service minecraft-server stop

and start it with the command

service minecraft-server start

Comments

comments

Annonse 2

Annonse 2

Be the first to comment

Leave a Reply