Choose a different version or distribution
Introduction
Before we begin talking about how to install Minecraft on Ubuntu 22.04, let’s briefly understand – What is Minecraft?
Minecraft is an immensely popular sandbox video game that lets players unleash their creativity and explore virtual worlds. Created by Mojang Studios, Minecraft offers endless possibilities, allowing players to build structures, mine resources, and embark on thrilling adventures. Its pixelated graphics and simple gameplay have captivated millions of players worldwide.
Whether you're constructing elaborate castles, surviving against hostile creatures, or collaborating with friends in multiplayer mode, Minecraft offers a captivating and immersive experience that has become a cultural phenomenon. Discover the limitless potential of Minecraft and let your imagination soar in this extraordinary virtual universe.
In this tutorial, you will Install Minecraft Server on Ubuntu 22.04. We will also address a few FAQs on how to install Minecraft Server on Ubuntu 22.04.
Advantages of Minecraft
- Creativity: Minecraft allows players to express their creativity by building and designing unique structures and landscapes.
- Exploration: With vast, procedurally generated worlds to discover, players can embark on exciting adventures and uncover hidden treasures.
- Multiplayer: Join forces with friends or connect with players worldwide, collaborating on massive construction projects or engaging in thrilling PvP battles.
- Educational: Minecraft promotes critical thinking, problem-solving, and resource management skills, making it a valuable educational tool for both children and adults.
- Endless Replayability: With its open-ended gameplay and a thriving modding community, Minecraft offers limitless possibilities, ensuring no two experiences are the same.
Prerequisites to Install Minecraft Server on Ubuntu 22.04
- A user with sudo privileges to be able to install the packages.
You will install the packages necessary to build the mcrcon
tool, by:
sudo apt update
sudo apt install git build-essential
Step 1 – Installing the Java Runtime Environment
1) Minecraft needs Java 8 version or greater. The Minecraft Server does not need a graphical user interface. So, install the headless version of JRE, as it is more suitable for server applications. Further, it has fewer dependencies as well as uses fewer system resources. To install the headless OpenJRE 8 package, run the following:
sudo apt install openjdk-8-jre-headless
2) Then, to verify the Java version installation, print:
java -version
You will see the following output:
Output
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
Step 2 – Creating the Minecraft User
1) Minecraft should never be run as a root user due to security concerns. You will have to create a new system user and group in a home directory /opt/minecraft
that will be used to run the Minecraft server.
sudo useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft
Step 3 – Install Minecraft on Ubuntu
1) Firstly, switch to the minecraft
user.
sudo su - minecraft
2) Create three new directories using the following command:
mkdir -p ~/{backups,tools,server}
- Backups directory for storing your server backup.
- Tools directory for storing the
mcrcon
client and the backup script. - Server directory for the actual Minecraft server and its data.
Downloading and Compiling
1) RCON protocol is used to connect to the Minecraft server and execute commands. You will need to download the source code from GitHub and build the mcrcon
binary.
2) Navigate to the ~/tools
directory and clone the Tiiffi/mcrcon
repository from GitHub.
cd ~/tools && git clone https://github.com/Tiiffi/mcrcon.git
3) Switch to the repository directory once the cloning is complete.
cd ~/tools/mcrcon
4) Compile the mcrcon
utility using the following command:
gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c
5) Test it once the compilation is done.
./mcrcon -h
You will get an output similar to below:
Output
Usage: mcrcon [OPTIONS]... [COMMANDS]...
Sends rcon commands to Minecraft server.
Option:
-h Print usage
-H Server address
-P Port (default is 25575)
-p Rcon password
-t Interactive terminal mode
-s Silent mode (do not print received packets)
-c Disable colors
-r Output raw packets (debugging and custom handling)
-v Output version information
Set Server address, port and password using following environment variables:
MCRCON_HOST
MCRCON_PORT
MCRCON_PASS
Command-line options will override environment variables.
Rcon commands with arguments must be enclosed in quotes.
Example:
mcrcon -H my.minecraft.server -p password "say Server is restarting!" save-all stop
mcrcon 0.6.1 (built: May 19 2019 23:39:16)
Report bugs to tiiffi_at_gmail_dot_com or https://github.com/Tiiffi/mcrcon/issues/
Step 4 – Downloading Minecraft Server
1) The Minecraft server mods like Craftbuk-kit or Spigot allows you to add features on the server. It further customizes as well as improves the server settings. You will now install the latest Mojang’s official vanilla Minecraft server.
2) Check the Minecraft download page before continuing with the next step.
3) After that, run the following wget
command. It will download the Minecraft jar file in the ~/server
directory:
wget https://launcher.mojang.com/v1/objects/ed76d597a44c5266be2a7fcd77a8270f1f0bc118/server.jar -P ~/server
Step 5 – Next Configuring the Minecraft Server
1) After the download is complete, you need to navigate to ~/server
directory and start the Minecraft server:
cd ~/server
java -Xmx1024M -Xms512M -jar server.jar nogui
2) After you will start the server for the first time, it executes some operations and will create both server.properties
and eula.txt
files and then stop.
[23:41:44] [main/ERROR]: Failed to load properties from file: server.properties
[23:41:45] [main/WARN]: Failed to load eula.txt
[23:41:45] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
3) You will need to agree to the Minecraft EULA, to run the server. Then open the eula.txt
file and change eula=false
to eula=true
:
nano ~/server/eula.txt
#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
#Sun May 19 23:41:45 PDT 2019
eula=true
4) Then, close and save the file.
5) After that, you will need to edit the server.properties
file. It will enable the rcon protocol and will set the rcon password. So, open the file using text-editor.
nano ~/server/server.properties
6) You will then locate the following lines to update their values as shown below:
rcon.port=25575
rcon.password=strong-password
enable-rcon=true
You can even adjust the server’s default properties. Visit the official server.properties page for more details.
Step 6 – Creating Systemd Unit File
1) Now, to run Minecraft as a service, you will create a new Systemd unit file.
2) Switch back to the sudo user by typing exit
.
3) After that, open the text editor and, then, create a file named minecraft.service
in /etc/systemd/system/
:
sudo nano /etc/systemd/system/minecraft.service
4) Now, paste the following configurations:
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=minecraft
Nice=1
KillMode=none
SuccessExitStatus=0 1
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/opt/minecraft/server
ExecStart=/usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui
ExecStop=/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password stop
[Install]
WantedBy=multi-user.target
5) You will need to modify both Xmx
and Xms
flags as per your server resources. Here, Xmx
flag means the maximum memory allocation for a Java virtual machine (JVM). While, the Xms
means the initial memory allocation pool. Also, make sure to use the correct rcon
port and password.
6) Then, save and close the file. Reload the systemd manager configuration using the following command:
sudo systemctl daemon-reload
7) Now you will start the Minecraft server by running:
sudo systemctl start minecraft
8) The first time you start the service, it will generate several configuration files and directories as well, including the Minecraft world. You will check the service status by running the following command:
sudo systemctl status minecraft
Output
* minecraft.service - Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2019-05-19 23:49:18 PDT; 9min ago
Main PID: 11262 (java)
Tasks: 19 (limit: 2319)
CGroup: /system.slice/minecraft.service
`-11262 /usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui
9) Finally, it will enable the Minecraft service to start automatically at boot time:
sudo systemctl enable minecraft
Step 7 – Adjusting the Firewall
1) If the server is protected by a firewall, and you want to access the Minecraft server from outside your local network. You will need to open the port 25565
.
2) Also, to allow the traffic on default Minecraft port 25565, run the following command:
sudo ufw allow 25565/tcp
Step 8 – Configuring the Backups
1) Now, you will create a backup shell script and cronjob. It will automatically back up the Minecraft server.
Start by switching to user minecraft
:
sudo su - minecraft
2) After that, open the text editor and create the following file:
nano /opt/minecraft/tools/backup.sh
3) After that, paste the below configurations:
#!/bin/bash
function rcon {
/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password "$1"
}
rcon "save-off"
rcon "save-all"
tar -cvpzf /opt/minecraft/backups/server-$(date +%F-%H-%M).tar.gz /opt/minecraft/server
rcon "save-on"
## Delete older backups
find /opt/minecraft/backups/ -type f -mtime +7 -name '*.gz' -delete
4) Next, you will need to save the file. Make the script executable by running the following chmod
command:
chmod +x /opt/minecraft/tools/backup.sh
5) Then create a cron job. It will run once in an entire day automatically at a fixed time.
Open the crontab file using the following command:
crontab -e
6) Now, run the backup script every day at around 21:00. You will paste the following line:
0 21 * * * /opt/minecraft/tools/backup.sh
Step 9 – Accessing the Minecraft Console
1) To have access to Minecraft Console, you will use the mcrcon
utility. Further, you need to mention the host, rcon-port, rcon-password, and use -t
switch. It will enable the mcrcon
terminal mode, by running:
/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password -t
The Output will be:
Logged in. Type "Q" to quit!
2) Also, when accessing the Minecraft Console from a remote location, make sure the rcon port is not blocked. If you are a regular user, instead of connecting to Minecraft console, you should create a bash alias.
FAQs to Install Minecraft Server on Ubuntu 22.04
What are the system requirements for running a Minecraft server on Ubuntu 22.04?
The recommended system requirements for a Minecraft server on Ubuntu 22.04 are at least 2 GB of RAM and a decent CPU. However, higher specifications may be required for larger player counts or modded servers.
How do I install Java on Ubuntu 22.04 for running a Minecraft server?
You can install Java by running the following command in the terminal: sudo apt install default-jre
. This will install the default Java Runtime Environment (JRE) on your system.
How can I download the Minecraft server software on Ubuntu 22.04?
You can download the Minecraft server software from the official Minecraft website. Visit the website and download the server JAR file, which you'll need to run the server.
How do I start the Minecraft server on Ubuntu 22.04?
To start the Minecraft server, navigate to the directory where the server JAR file is located using the terminal. Then, run the following command: java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
. Adjust the memory values as per your server's requirements.
How do I configure the Minecraft server properties on Ubuntu 22.04?
The server properties file is named server.properties
and it is created when you run the server for the first time. You can modify this file using a text editor to change various server settings such as the game mode, difficulty, or server name.
Can I run a Minecraft server on Ubuntu 22.04 without a GUI?
Yes, it is possible to run a Minecraft server on Ubuntu 22.04 without a GUI. In fact, it is recommended to run the server in a headless mode without a graphical user interface for better performance.
How do I connect to my Minecraft server running on Ubuntu 22.04?
To connect to your Minecraft server, launch the Minecraft game, click on Multiplayer
, then Add Server
. Enter the server's IP address or domain name and click Done
. Finally, select the server from the list and click Join Server
to connect.
How can I make my Minecraft server accessible to players outside my local network on Ubuntu 22.04?
You need to configure port forwarding on your router to make the Minecraft server accessible to players outside your local network. Open your router's settings, locate the port forwarding section, and forward the Minecraft server port (default is 25565) to the local IP address of your server.
Can I install plugins or mods on my Minecraft server running on Ubuntu 22.04?
Yes, you can install plugins or mods on your Minecraft server. There are several popular servers modding platforms like Bukkit, Spigot, or Paper, which allow you to install plugins. Make sure to follow the instructions provided by the specific modding platform.
Conclusion
Hope this detailed tutorial helped you understand how to install Minecraft Server on Ubuntu 22.04.
To learn more about Minecraft installation, check out the official Minecraft installation document.