Minecraft - How to install & setup on Ubuntu

# How To: Minecraft Server on Ubuntu

Posted on June 13, 2014 by c0mputer0 — 74 Comments

So I’ve been playing Minecraft on the Xbox360 for some time now and it started getting a bit repetitious and bland. My son got into the PC version and I was sitting with him and his friends for a few sessions and it got my interest. This weekend I decided to set up a server so they can have somewhere to put their creations and not have to worry about being kicked from someone else’s server or have their city griefed (*Griefing is the act of irritating and angering people in video games through the use of destruction, construction, or social engineering.*) as well, they were talking about starting to make YouTube vids so this will be good for them. I thought this would have been harder that what it turned out to be, so for those wanting to do it but are not sure about how go about it or are afraid of getting their hands dirty in Linux, I created this tutorial.

## What is Minecraft?

Minecraft is basically and electronic version of Lego but with so much more. The Xbox version is limited but the PC version is just too awesome and huge to put into words in a post as there are so many features and not to mention the mods and customizations that can be made to it. If you are into developing or know how to script you can create your own customization for Minecraft to make your install yours. As always, if you create something awesome, do share with others. At the end of the article I will post links to related sites.

Minecraft is basically a sandbox game where players can break and place blocks to build almost infinite creations. Blocks or Cubes are scaled to 1 cubic Meter and represent different materials like dirt, stone, water, lava, trees and various ores. At start, players spawn with nothing but their two hands and an open world to explore, worlds are divided into biomes ranging from deserts to snowfields. The game has a day-night system as well as a varied weather cycles depending on what biome you are in; like snowfall if you are in a snow biome or rain if you are in another biome.

As the game progresses, players will meet non playable characters knows as mobs. They include non-hostile mobs such as chickens, cows and pigs that can be killed for food, leather or wool and these may change. In the night-time and in dark areas, hostile mobs are set loose, they include giant spiders, skeletons, zombies and creepers. Skeletons come armed with bow and arrows and creepers are equipped with an explosive charge that go off if they get close to you, they make no noise except for the hiss right before they explode. There are other mobs in the game but we won’t go into them all as each version of the game and the platform you play them on present different features and it is too much for this post. Depending on what version you are playing you may have different mobs as well like wolves (non-hostile mobs like wolves will attack if you hit one, then all hell breaks loose; especially if they are in a pack when you do).

Minecraft allows for some sick in-game creations with just the blocks you find in game, even if you have no added mods; for example, with redstone you can create electrical circuits to build primitive mechanics, electrical circuits and logic gates. For example, you can build automatic doors, cannons, timers and more.

There are numerous expansions that you can add to the game, like mod packs, texture packs, resource packs and custom maps. Mods allows one to add features to the game like elements from Portal and The Hunger Games. The Modding community is HUGE, but keep in mind that mods are developed for specific Minecraft Versions.

Update: *Minecraft has since been bought by Microsoft as of the Sept 2014 for $2.5 Billion Dollars. Read the release here.*

Ok, now back to the reason you came here in the first place…

## How to setup your own server in Ubuntu.

While I set mine up using Ubuntu 12.04, you can choose to use other Linux variants and switch the commands to suite your OS of choice. The reason I used Ubuntu 12.04 is that it is an LTS (Long Term Support) version and will receive support for 5 years which gives me to April of 2017 until I have to upgrade the OS and I prefer to keep with a stable system. For those that don’t know, Ubuntu releases LTS and non LTS versions of their OS; their naming convention rolls with their release schedule, April and October of every year which gives us a 6 month cycle. :) I will be upgrading sooner or later but I prefer to let the kinks be ironed out before I move on, I’m not a bleeding edge person in this respect. Below is a list of their last few releases.

* Ubuntu 12.04.\* LTS (Precise Pangolin)
* Ubuntu 14.04 LTS (Trusty Tahr)
* Ubuntu 14.10 (Utopic Unicorn)
* Ubuntu 15.04 (Vivid Vervet)

Edit: I am thinking about switching to 14.04, not sure if I want to upgrade or just build a new server and migrate all my Minecraft data. Will keep you posted.

## First things First

I am assuming that you have already installed your Ubuntu OS; if not, go do that before moving ahead. If you are not sure how to do so, I recommend a quick Google search. You WILL want to select the OpenSSH Server option at the Software Selection screen. I am also assuming that you have some basic knowledge of Ubuntu and the Command Line. The tutorial will be broken up into sections and will cover most things that are needed for running Minecraft as well as securing your server.

### Required Packages

These packages are needed before we can proceed any further as well as updating your system before we proceed any further. Make sure you have the right apt setup, see here.

### Updating and Upgrading

```
sudo apt-get update && sudo apt-get upgrade
sudo apt-get update && sudo apt-get dist-upgrade

```

### Open-SSH / VIM

SSH allows you to connect to your server from another computer for administration, maintenance or troubleshooting. If you did not select this during setup, here is how to install it. Vim will be used to edit files, you can use a different editor if you have a favorite like nano.

```
sudo apt-get install openssh-server vim

```

### UFW – Uncomplicated Fire Wall

UFW is installed by default on most Linux systems, but is not enabled. This means your server is wide open to the entire world. Let’s enable the firewall but first we must add a rule to allow SSH or you will not be able to connect once the firewalls is enabled.

```
sudo ufw allow 22

```

Once that rule has been added then we can enable the firewall:

```
sudo ufw enable

```

Now we need to enable the other ports we are going to be using. Minecraft runs on a default port of 25565. Run the following command to add the port.

```
sudo ufw allow 25565

```

Check the Firewall status to make sure all is setup right:

```
sudo ufw status

```

You should see the following:

```
Status: active
 To                         Action      From
 --                         ------      ----
 22                         ALLOW       Anywhere
 25565                      ALLOW       Anywhere
 22                         ALLOW       Anywhere (v6)
 25565                      ALLOW       Anywhere (v6)

```

### fail2ban

This is a neat little package that keeps track of how many times someone has tried to login to your server (not your MC server, your actual Linux server), and then bans their IP address for a set period of time when someone tries to login via SSH.

Run the command and tell it Yes when it asks if you want to install:

```
sudo apt-get install fail2ban

```

The default install on this will probably be fine for you, but you can look at the specific settings in /etc/fail2ban/jail.conf, I use vi to edit.

```
sudo vi /etc/fail2ban/jail.conf

```

The Default section contains the default ban length and max retries for all services. You can also set your own IP address to be ignored if you want. The ban time is in seconds, I suggest setting that to a minimum of 24 hours to prevent script kiddies from trying to brute force your machine all day long.

```
[DEFAULT]
# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1/8
bantime  = 86400
maxretry = 3

```

The SSH section has a different number set for max retry that overrides the default settings. You can change this or leave it as you see fit.

```
[ssh]
enabled  = true
port     = ssh
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 6

```

Optimize fail2ban

```
sudo vi /etc/default/fail2ban

```

Add the following line:

```
ulimit -s 256

```

Restart fail2ban

```
sudo /etc/init.d/fail2ban stop
sudo /etc/init.d/fail2ban start

```

### htop

This is an awesome tool to keep track of CPU and MEM usage, we use it with Shift+M to list usage by memory (highest at the top). To use it simply type htop on the command line then once it’s started use the Shift+M key combination to sort by memory usage.

```
sudo apt-get install htop

```

### Java

Java is NOT optional, without this Minecraft will NOT run. To install it run the following:

```
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update && sudo apt-get install oracle-java8-installer

```

## Users, Folders and Rights

For security reasons we do NOT want to run Minecraft as root so we will create a minecraft user for this purpose as well as create admin accounts that can edit files and configs for the Minecraft server. Make sure you are using secure passwords, read our article on that here.
Create the minecraft user:

```
sudo adduser minecraft

```

Create additional users and add them to the minecraft group as needed.

```
sudo adduser username
sudo usermod -a -G minecraft username

```

The groups command will check the groups a user belongs to so you can make sure they are in the minecraft group.

```
groups username

```

### Where to put the files

You can put the files anywhere you’d like but we prefer to create a root directory to keep everything centralized. We’ll create all the directories first and then assign rights and run modes after.

```
cd /
sudo mkdir minecraft

```

Next, create backup directories, we all know how important backups are right?

```
sudo mkdir minecraft/backups

```

Assign ownership of the minecraft directory tree to the minecraft user and group as well as set proper run mode.

```
cd /
sudo chown -R minecraft:minecraft minecraft
sudo chmod -R 775 minecraft

```

### Getting the files and performing first run

Before we do anything else we need to grab the server file and perform a first run to get things setup.
Make sure you are in the minecraft directory before proceeding:

```
cd /minecraft

```

Become the minecraft user

```
su - minecraft

```

To get the server file go here and download the latest server file, as of this writing it is minecraft\_server.1.8.7.jar. I use wget for my files so copy the URL to the latest download then run this, remember to change the url to the one you copied:

```
wget https://s3.amazonaws.com/Minecraft.Download/versions/1.8.7/minecraft\_server.1.8.7.jar

```

Rename the downloaded file

```
sudo mv minecraft_server.1.8.7.jar minecraft_server.jar

```

### Test it out

The following command will start the server, run it with no gui and assign 2GB of ram to the server. Make sure you use an appropriate number depending how much ram your system actually has, this is set in MB so 1GB would be 1024.

Get back into the minecraft directory

```
cd /minecraft

```

Start minecraft

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

```

During the run you should see a console that will show you the progress of the setup. Once the run is finished you should be able to connect and play.

Once verified, type `stop` in the console to stop the server so we can proceed.

### Editing settings

Enable the whitelist so that nobody can connect while you are working on your server.

* Set yourself as an op in ops.txt
* Set your IP address
* Set any other options you want on your world, such as enabling PvP or Monsters or whatever.

Here is a copy of my server.properties file. The lines in orange are ones that you will need to modify. As per Minecraft, here are the options for op-permission-level:

1. Ops can bypass spawn protection.
2. Ops can use /clear, /difficulty, /effect, /gamemode, /gamerule, /give, and /tp, and can edit command blocks.
3. Ops can use /ban, /deop, /kick, and /op.
4. Ops can use /stop.

```
#Minecraft server properties
allow-flight=false
allow-nether=true
announce-player-achievements=true
difficulty=1
enable-command-block=false
enable-query=false
enable-rcon=false
enable-command-block=false
force-gamemode=false
gamemode=0
generate-structures=true
generator-settings=
hardcore=false
level-seed=whatever seed you want
level-name=My World
level-type=DEFAULT
max-build-height=256
max-players=20
motd=Welcome to My World ツ
online-mode=true
op-permission-level=2
player-idle-timeout=0
pvp=true
resource-pack=
server-ip=xxx.xxx.xxx.xxx
server-port=25565
snooper-enabled=true
spawn-animals=true
spawn-monsters=true
spawn-npcs=true
spawn-protection=16
view-distance=8
white-list=false

```

The ip address will be the address of the server and is for local connection only. For connecting from outside your local network you will need to setup port forwarding and maybe Dynamic DNS settings. These are way too involved to cover here so as usual, Google is your friend.

Enabling whitelisting will create a setup where no one will be able to connect unless they are whitelisted.

I suggest changing the view-distance to 7 to reduce possible lag. This setting handles the way the game loads chunks.

### Making it easy

Make sure you are in the minecraft directory still:

```
pwd

```

which should give you an output like this:

```
/minecraft

```

Instead of having to run the long command every time we want to start the server, we’ll create an executable that we can run to do it. Create a new file called `vanilla.sh` and edit it, I use vim but you can do this in your favorite editor as well.

```
vi vanilla.sh

```

Press `i` to enter interactive/edit mode and paste in the following:

2
3
4
5
`java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui`
`# Log all reboot startups to keep track`
`exec` `echo` `Minecraft server was started/re-started` `on `date` &gt;&gt; /var/log/minecraft.log`

Save and quit:
`:wq` and press `Enter`

Make the new file executable by running the following command:

```
chmod +x vanilla.sh

```

To start the server now all you have to do is run the following command as the minecraft user:

```
./vanilla.sh

```

## Modded Runs

Here are links to some of the Mod Packs available online.

* Tekkit
* Hexxit
* BigDig
* Voltz
* Bukkit

## Screen

Screen is a console application that allows you to use multiple terminal sessions within one window. One of the advantages of screen that is you can detach it. Then, you can restore it without losing anything you have done on the screen. There are many situations where creating several terminal windows is not possible or ideal. This will be beneficial if you want to run your server on a cloud or a VM (Virtual Machine) session, as Darkside mentioned in the comments.

### Installing Screen

```
sudo apt-get update && sudo apt-get install screen

```

### Using Screen

To start a new screen session, we simply type the `screen` command.

```
screen

```

Accept the License by pressing `Enter` as instructed.

Once done you will be dropped back to a normal looking shell. What? Did I mess something up you ask? No, no you did not. To verify that you are on track, issue `Ctrl+a` the press `v`, which should respond with the Screen version:

```
screen 4.01.devel (GNU) 2-May-06

```

Every keyboard shortcut for screen is prefaced with `Ctrl-a` (hold the control key while pressing the `a` key). That sequence of keystrokes tells screen that it needs to pay attention to the next keys we press.

To get a full list of options press `Ctrl+a` the press `v`, which will print out the following list:

```
Screen key bindings, page 1 of 1.

                          Command key:  ^A   Literal ^A:  a

    break       ^B b           license     ,              removebuf   =
    clear       C              lockscreen  ^X x           reset       Z
    colon       :              log         H              screen      ^C c
    copy        ^[ [           login       L              select      '
    detach      ^D d           meta        a              silence     _
    digraph     ^V             monitor     M              split       S
    displays    *              next        ^@ ^N sp n     suspend     ^Z z
    dumptermcap .              number      N              time        ^T t
    fit         F              only        Q              title       A
    flow        ^F f           other       ^A             vbell       ^G
    focus       ^I             pow_break   B              version     v
    hardcopy    h              pow_detach  D              width       W
    help        ?              prev        ^H ^P p ^?     windows     ^W w
    history     { }            quit        \              wrap        ^R r
    info        i              readbuf
    kill        K k            redisplay   ^L l           xoff        ^S s
    lastmsg     ^M m           remove      X              xon         ^Q q

^]   paste .
"    windowlist -b
-    select -
0    select 0
1    select 1
2    select 2
3    select 3
4    select 4
5    select 5
6    select 6
7    select 7
8    select 8
9    select 9
I    login on
O    login off
]    paste .
 :kB: focus prev

```

### Let’s test it out shall we?

Let’s say we want to run our Minecraft session but continue to work on the server, let’s say yu want to download a pack of some sort and it will take some time. Start screen:

```
screen

```

You start your minecraft session:

```
cd /minecraft
./vanilla.sh

```

Now detach from that screen so you can do your other work by issuing `Ctrl+a` the press `d`. You should now see a default shell. To re-connect to your sessions, run the following command:

```
screen -r

```

Note:
When you have more than 1 screen session, you need to type the screen session ID.

To see how many screen are available, issue the following command

```
screen -ls

```

Which will output something like this:

```
There is a screen on:
        17448.pts-0.minecraft   (01/27/2015 09:48:30 PM)        (Attached)

```

To connect to your seesion again you will need the session id, which in our example is `17448.pts-0`. To connect to that session run the following command:

```
screen -r 17448

```

### Moving about in screen

When you do nested screen, you can switch between screen using command `Ctrl-A` the press `n`. It will be move to the next screen. When you need to go to the previous screen, just press `Ctrl-A` the press `p`.

### Leaving Screen

There are two ways to end your screen sessions. First, is `Ctrl-A` the press `d` to detach the screen. Second, we can use the exit command to terminating screen. You also can use `Ctrl-A` the press `K` to kill the screen.

## Execute Cron Job After System Reboot

crontab is the program used to install, deinstall or list the tables used to drive the cron daemon in Vixie Cron.

Become the minecraft user:

```
sudo -s

```

```
su - minecraft

```

Start the cron editor as the minecraft user:

```
crontab -e

```

You can also use this as root (sudo -s)

```
crontab -e -u minecraft

```

In the editor, paste the following line:

`@reboot /minecraft/vanilla.sh`

Run the following command to finish:

```
update-rc.d cron defaults

```

Source: https://computerobz.wordpress.com/2014/06/13/how-to-minecraft-server-on-ubuntu/