Knowledgebase

Install Minecraft on your Linux VPS

The beauty of having your own Minecraft server is that you are totally in charge of your gaming experience. You have the control on all the settings and mods used by the server, you can set admin advantages for players. You can even decide to make your server private or make it public for everyone to access.

This guide is based on a Ubuntu 20.04 Focal Fossa installation.

Linux is known for its stability when running servers and Ubuntu is known for its ease of use.

If you do not own your Linux VPS yet, get yourself one by ordering here.

In this guide, you will learn:

  1. How to install and configure a Minecraft Server on your Linux VPS
  2. Create a Minecraft systemd startup script
  3. Monitor your Minecraft Server

Install Prerequisites

This guide assumes you are logged into your server. If you are not logged yet or do not know how to loggin, please follow these guides :

There are a few packages we need to install to run a Minecraft Server. Let's start by installing them.

Open your terminal and type the following two commands :

$ sudo apt update
$ sudo apt install wget screen default-jdk nmap
  • wget will be used to download Minecraft Server files
  • screen is for running the Minecraft Server in the background
  • default-jdk is a Java package that Minecraft needs in order to run
  • nmap will be used later for basic troubleshooting purposes

Create a Minecraft user

It is a good practice to let the Minecraft Server run under its own dedicated account, rather than using root user. You can create a new account with the following command :

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

Install Minecraft Server

It is possible to run multiple instances of a Minecraft Server on a single Linux VPS. Each server instance you will run need its own directory under the /opt/minecraft directory. 

For this instance, let's call it survival and create the following directory : 

$ sudo mkdir /opt/minecraft/survival

Once the directory is created, we need to download the official Minecraft Server Java file with wget. Since Minecraft receives regular updates, we will share your the latest version file :

  1. Go on this page and locate the download link
  2. Right-click and select Copy link address on the line Download minecraft_server.X.XX.X.jar and run it with the following command:

Use the following command to download the file, replacing the link in this example with the current copied link  :

$ sudo wget -O /opt/minecraft/survival/minecraft_server.jar https://launcher.mojang.com/v1/objects/f02f4473dbf152c23d7d484952121db0b36698cb/server.jar

Once the download is completed, you will need to accept the EULA before being able to install Minecraft Server.

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

And finally, we will need to give our minecraft user account ownership on the Minecraft Server survival directory :

$ sudo chown -R minecraft /opt/minecraft/survival/

Create the Minecraft systemd startup script

Start by creating a new named [email protected] file with nano command : 

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

And then paste the following content in the new file :

[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 minecraft_server.jar nogui

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


[Install]
WantedBy=multi-user.target

Memory allocation

Based on your Linux VPS Plan, you can edit the amount of memory the server needs to allocate for the Minecraft Server. In the example above, we are allocating 2GB of memory. If you would like to allocate more - like 6GB, for example, you will need to do the following change : 

From

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

To

ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx6G -jar minecraft_server.jar nogui

You can save your changes and exit the file.

Start the Minecraft Server

To start a Minecraft Server, we will use the following command systemctl to place things up :

$ sudo systemctl start minecraft@survival

You can confirm that everything is working and make sure it is up and running with the following command : 

$ sudo systemctl status minecraft@survival

Let Minecraft Server starts automatically (optionnal)

To let Minecraft Server starts automatically every time the system reboot, type the following command : 

$ sudo systemctl enable minecraft@survival

Watch for incoming connections

To make sure your Minecraft Server is listening for incoming connections, use the nmap command :

$ nmap -p 25565 localhost

Note : the default Minecraft Server port is 25565. If you want to run multiple Minecraft Servers on the same host, you would need to change the port.

As long as nmap shows that Minecraft is listening on the correct port, your server is good to go. All you need to do is to log yourself on the server from the Minecraft game client.

Happy gaming!

 

134 Users Found This Useful

Was this answer helpful?

Didn't find a solution?

Our support team is here to help you.

Contact us by sending a support ticket.

Open a ticket

Powered by WHMCompleteSolution