Setting up a Minecraft Server on Ubuntu

Setting up a Minecraft Server on Ubuntu


In this tutorial, I'm going to use my server hosted on DigitalOcean as an example.
This server is actually a virtual machine (called Droplet by DigitalOcean). I bought the lowest cost plan ($5 per month) with 512MB RAM, 20GB SSD, and Ubuntu 14.04 installed. This is sufficient for a Minecraft server. The ONLY thing you need to do to set up the environment is installing Java.

Install Java
Run the following commands in this order to add the PPA, update the source list and then install java:

sudo apt-add-repository ppa:webupd8team/java  
sudo apt-get update  
sudo apt-get install oracle-java7-installer  

Check Java Version
Then run this to check what version you have installed:

java -version  

The output should be similar to:

java version "1.7.0_80"  
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)  
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)  

Server File

Download the server application file from the Minecraft download page, look for Multiplayer Server, for example, minecraft_server.1.8.9.jar.
You can download this file directly from your server, or upload to your server through FTP.

Add Swap

For a server machine like what I used does not have enough RAM to run the Minecraft server, which requires 1024MB RAM. You cannot start the server application if your system does not have enough free memory. To solve this problem, we need to add a swap file.

We can create a 1 Gigabyte swap file by typing:

sudo fallocate -l 4G /swapfile  

Then we can verify that the correct amount of space was reserved by typing:

ls -lh /swapfile  
-rw-r--r-- 1 root root 1.0G Jan  3 23:13 /swapfile

Locking down the permissions by typing:

sudo chmod 600 /swapfile  

Tell the system to set up the swap space:

sudo mkswap /swapfile  

Finally, enable the swap space by typing:

sudo swapon /swapfile  

For more information (such as how to make the swap file permanent),

Run Server

We want to keep the server application running even when we exit the ssh session. So we run the server in a Screen session.
To learn Screen installation and usage, read the last part of this blog article, Keep your processes running after disconnect.

Inside the Screen sessioon, run:

java -Xms1024M -Xmx1024M -jar minecraft_server.1.8.9.jar nogui  

Remember to create a folder for this Minecraft server application, because a bunch of files will be generated in the same directory as the jar file.
Then you will be asked to edit the eula.txt file to signify that you have read and understood the end user license agreement that you'll follow when using the software. Just change false to true.
Then run the command again.

That's it! Now you can detach the Screen session by pressing Ctrl + A + D, and enjoy the Minecraft world with your friends.

Restart Server Automatically After Crash

while true  
java -Xms1024M -Xmx1024M -jar minecraft_server.1.8.9.jar nogui  
echo "If you want to completely stop the server process now, press Ctrl+C before  
the time is up!"  
echo "Rebooting in:"  
for i in 5 4 3 2 1  
echo "$i..."  
sleep 1  
echo "Rebooting now!"  

Use ctrl + c before the server auto restarts when you use /stop to stop the process completely.


More: Game, Minecraft