Minecraft is very popular sandbox game that is played by kids and grownups across entire globe. In this article we will show how to install a Minecraft server to play Minecraft with your friends in your own virtual world. You would need to buy the Minecraft game, to play it, and your friends will need also. Game is written in Java so it can be played on Linux, macOS or Windows. We are going to install server on Ubuntu and play the game also on Ubuntu. Server will be installed on cloud node (say digitalocean, aws, linode and rackspace), and not on localhost, although you can also do it on localhost. In that case it will be probably accessible only in your home network unless you have public IP.
How to Install Minecraft Server
First of all we need to install Java. The Minecraft documents recommend Sun JDK 6 but that is fairly outdated and since then OpenJDK have become de facto standard, so we can use OpenJDK 8 and sidestep proprietary Oracle JDK. So lets install it:
sudo apt install openjdk-8-jre
In order to achieve better security, it is advisable to not run Minecraft server as root user. So we will create a minecraft user and add it to minecraft group
adduser minecraft
groupadd minecraft
usermod -a -G minecraft minecraft
After this have been done we can log in as minecraft user in order to install the minecraft server
su minecraft
We would also need to cd to home because we donw want minecraft user to download to root directory, he has no write rights there.
cd
And next we download the current version (1.10.2 ) of minecraft server
wget https://s3.amazonaws.com/Minecraft.Download/versions/1.10.2/minecraft_server.1.10.2.jar
We will rename the server in such a way that it removes the version number. This is done so you can easier update it later, simply by swaping the binary.
mv minecraft_server.1.10.2.jar minecraft_server.jar
Next we can start the server for the first time:
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
This first run will be unsucessful because we need to accept the EULA. The first run have created eula.txt file which we now need to edit to accept EULA. This command will do the trick
sed -i.orig 's/eula=false/eula=true/g' eula.txt
Next we can run it again.
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
After this server should start and you can type the ip address of your server in the game to connect.
Connecting to the server
Now that we have server up and running, we need to get our game to connect. As mentioned, we assume that you bought the game, we will not tell you how to get the game for free and we don't know if that is even possible. If you bought the game, you will have the multiplayer option unlocked, and that is what you need to connect to the server. In order to test we bought license for $26.95 and you can download them any number of times from any number of computers. If you didn't already do so, download the latest client from Minecraft official site. Add executable bit to the file
chmod +x minecraft.jar
Next you can double-click on the jar file or right click it and select it to be started with OpeJDK. There you type credentials of your account that you used to buy the game

After entering your user name and password, you should be presented with next screen

After entering multiplayer, there are normally no servers there. We need to add the server we just set up.

Adding server is easy, just enter ip address. And Server Name can be any, that is just how server is called on the list.

After we add server it will show up on the list and next we can connect to it. After we connect to the game, the the server console should display following message
[Server thread/INFO]: LinoxideBlaster joined the game
Off course your username would be different.

after you finished playing, and exited, the console will show something similar to this:
[Server thread/INFO]: LinoxideBlaster left the game
Making a systemd unit file
After seeing that all works well, you want to close the terminal window with SSH session on the server. But that will turn off the Minecraft server as well, as it is running in foreground mode. So we need a startup script which will make it run in background and start with the system. So lets make one.
First we need to close previous instance of the Minecraft server that ran in foreground. Just press Ctrl-C and it will close. Next we need to login as root.
su
Lets then make new file, that will become our script
nano /etc/systemd/system/minecraft-server.service
There we will paste this:
[Unit]
Description=start and stop the minecraft-server
[Service]
WorkingDirectory=/home/minecraft
User=minecraft
Group=minecraft
Restart=on-failure
RestartSec=20 5
ExecStart=/usr/bin/java -Xms1536M -Xmx1536M -jar minecraft_server.jar nogui
[Install]
WantedBy=multi-user.target
Alias=minecraft.service
Next we can start the service:
systemctl start minecraft-server.service
And enable it at system startup
systemctl enable minecraft-server.service
Conclusion
So we created our own server for Minecraft on Ubuntu. This game is addictive enough and can burn you a lot of time so be sore to forget about your chores while playing it. As for hardware requirements, Mojang site lists this
- CPU: Intel Pentium D or AMD Athlon 64 (K8) 2.6 GHz.
- RAM: 2GB.
- GPU (Integrated): Intel HD Graphics or AMD (formerly ATI) Radeon HD Graphics with OpenGL 2.1.
- GPU (Discrete): Nvidia GeForce 9600 GT or AMD Radeon HD 2400 with OpenGL 3.1.
- HDD: At least 200MB for Game Core and Other Files.
- Java 6 Release 45.
I have been playing it without trouble on Thinkpad X220T with Intel sandy Bridge HD3000 graphics, and my cousin have reported trouble on windows with Radeon Mobility 2400 which is bare minimum, according to Mojang. It is not really demanding game. So happy playing and have a nice day.
What about SELinux policy and firewall exceptions?
Thanks!
Will have this topic in a future article
Thanks, great explaination. Especially liked the systemctl sectionion. Concise and to the point.
Have a fun day!
Does this still work? i mean..
systemctl start minecraft-server.service
Isn't working :(
Failed to start minecraft-server.service: Unit minecraft-server.service is not loaded properly: Bad message.
See system logs and 'systemctl status minecraft-server.service' for details.
what does logs and 'systemctl status minecraft-server.service' says ?
this worked for me
[Unit]
Description=start and stop the minecraft-server
[Service]
WorkingDirectory=/home/minecraft
User=minecraft
Group=minecraft
Restart=on-failure
RestartSec=20 5
ExecStart=/usr/bin/java -Xms1536M -Xmx1536M -jar minecraft_server.jar nogui
[Install]
WantedBy=multi-user.target
Alias=minecraft.service
I've gotten my server working but I have noticed there is no way to access the server console while it is running, am I missing something or is there a workaround for this?