This tutorial describes how to setup a Minecraft server. Following the steps in this tutorial, you will be able to run a Minecraft server on a home computer. This tutorial describes how to setup Minecraft on a server running a Debian based Linux operating system. You will have to modify the instructions if you are using a different distribution.
This tutorial is intended for people with minimal knowledge of Linux and the internet. You should know how to start the linux terminal on your server machines. The instructions in this tutorial will cover all of the commands you must use and the files you must edit to get your Minecraft server setup and running.
In this tutorial you will learn
- How to create a user and group to run the Minecraft server.
- How to get the latest version of Minecraft server java application.
- How to create a startup script so your server starts when the server boots up
- How to use the minecraft script to administer the server while it is running.
Note: This tutorial describes how to setup a ‘vanilla’ minecraft server. All the cool kids are using the Craftbukkit server because of the ability to install plugins and game modifications. However, due to open source license and copyright disputes, it is no longer possible to legally download the Craftbukkit server application.
Before You Start
Hosting Web Servers at Home
If you are not an IT pro, or unless you are adventurous and laugh in the face of danger, then you should never operate servers exposed to the internet on the same local area network (LAN) where you have your personal computers. If you want to operate web servers from your home internet connection, I recommend that you use multiple routers to create a secure setup. Setting up your home routers to create a secure isolated subnetwork is described in our tutorial here.
If you wish to administer your web server machine from a computer on an isolated side of your network, you should also read our tutorial about router configuration and port forwarding here.
Make sure you have the latest java runtime environment. As of December 2014, this is version 7. To install the java runtime:
$ sudo apt-get install openjdk-7-jre
You will also need two packages for the administrator scripts:
$ sudo apt-get install screen
$ sudo apt-get install rsync
Create Minecraft User
It is important to create a specific user to run the Minecraft application. You want to avoid running Minecraft as a super user in case the java application gets hacked. This could lead to the scenario where hackers have super user control over your server machine.
To create a new user, log into the server with your regular username, then:
1. Create a new group called ‘minecraft’
$ sudo addgroup --system minecraft
2. Create a new user called ‘minecraft’ in the minecraft group.
$ sudo useradd -g minecraft -d /home/minecraft -m minecraft
3. Set the password for the minecraft user
$ sudo passwd minecraft
Get the Minecraft Files
1. Switch to the minecraft user, then create a directory for the minecraft server application
$ su minecraft $ cd ~ $ mkdir src
2. Get the latest minecraft server in this directory. Note, replace .X.Y.Z with the latest version number of the minecraft server. As of December 2014, this is 1.8.1.
$ cd /home/minecraft/src $ wget -O minecraft_server.jar https://s3.amazonaws.com/Minecraft.Download/versions/X.Y.Z/minecraft_server.X.Y.Z.jar
3. Test the server. In the /home/minecraft/srv directory, enter the following into the terminal:
$ java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
You will notice some warnings about missing files, don’t worry about this the files are created the first time you run the Minecraft server application. However, you will also notice that your server does not start, and in the console there is a message about needing to accept the EULA before you can run the server. To accept the EULA:
1. Open up the eula.txt file
$ nano /home/minecraft/srv/eula.txt
2. Change the line that says eula=false to eula=true.
3. Restart the Minecraft server with the command from step 3 above.
You should now be able to connect to your minecraft server on the default port 25565. You could stop here, but if you want Minecraft to start automatically when the server boots up you should make a startup script.
Create a Minecraft Script
A script can be used to not only start and stop the Minecraft server, but also to provide useful server administrator functionality. For our server, we use this script: https://github.com/Ahtenus/minecraft-init . To setup this script on your server machine:
1. Get the script file from GitHub.
$ cd ~ $ git clone https://github.com/Ahtenus/minecraft-init.git
2. Create a config file from the config.example file, and modify it to match your installation
$ cd minecraft-init $ cp config.example config $ nano config
a. Check the name of the Minecraft jar file on the MC_JAR= line
b. Specify that you are using the Minecraft jar file on the SERVICE= line.
c. Set the proper path to the jar file on the MCPATH= line
d. Set the initial and maximum amount of memory for the java virtual machine on the INITMEM= and MAXMEM=
3. Create a link to the script in the init.d directory, and register it as a startup program and service. As the root user
$ sudo ln -s /home/minecraft/minecraft-init/minecraft /etc/init.d/minecraft $ sudo chmod 755 /home/minecraft/minecraft-init/minecraft $ sudo update-rc.d minecraft defaults
4. Test the script. As the minecraft user
$ service minecraft start
Wait a minute for the server to start, then you can check the status
$ service minecraft status
You can also get access to the terminal screen that Minecraft is running in using the script
$ service minecraft screen
Your Minecraft server is all set up and ready to go.