Jump to content

How to host a Minecraft server on Ubuntu 12.04


Recommended Posts

Minecraft, now with over 7,000,000 purchases, is truly a fantastic game. One of the best extensions of Minecraft is the multiplayer side, so right here we're going to show you the quick and easy way of hosting a server on Ubuntu 12.04. It should be of note that this guide should also work for a whole mix of Linux distributions and versions, so don't think these instructions are isolated to Ubuntu 12.04.

Let's get started, shall we?


Before we begin, let's make sure we have a few essentials. All we'll be needing is Java and Screen, a utility that allows us to run applications on virtual "screens" (like tty for experienced users). First, let's focus on grabbing Java. In the terminal, let's run the following commands to get our hands on the Java RunTime Environment 6 (recommended for Minecraft):

sudo wget https://github.com/flexiondotorg/oab-java6/raw/0.2.3/oab-java.sh -O oab-java.sh
sudo chmod +x oab-java.sh
sudo ./oab-java.sh
sudo apt-get install sun-java6-jre
sudo apt-get install sun-java6-plugin sun-java6-fonts[/CODE]

You might get a few prompts along the way asking you to confirm some actions; you'll want to hit [b]Y[/b] for those.

Next let's look at getting screen. This one's a lot easier.

[CODE=bash]sudo apt-get install screen[/CODE]

Easy, right?

[h1]Downloading Minecraft[/h1]

Let's download Minecraft to our server. It's really, really simple. All we have to do is grab one file from Minecraft's servers and we're set! First, however, here's something to consider. If you'd like a server with mods on, you'll want to use Bukkit. Bukkit is a separate entity that works with Mojang (the creators of Minecraft) to produce a modding API; if you want mods on your server, you want Bukkit.

Putting that aside, however, let's first create a user for Minecraft so that anyone else we want to help manage the server can just have access to that user and not the whole server! Let's make it simple and call our user [b]minecraft[/b]. Run the following commands to do so:

[CODE=bash]useradd -m -s /bin/bash minecraft
passwd minecraft[/CODE]

After you type [b]passwd minecraft[/b] it will ask you to type in the password you'd like for the new user. It'll look like nothing's being typed, but it's just hiding what you type in-case anyone's behind you!

Let's switch to our new user by using the following command:

[CODE=bash]su minecraft[/CODE]

You'll be asked to type the password you just defined and then you'll be in!

Now, if you'd like a normal, plain, vanilla server, use the following command to grab it from Minecraft's servers:

[CODE=bash]wget https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar[/CODE]

If you'd instead like a moddable server (using Bukkit), use this command instead:

[CODE=bash]wget http://dl.bukkit.org/latest-rb/craftbukkit.jar[/CODE]

Brilliant! You've now downloaded Minecraft to your server! Time to get it started.

[h1]Creating a Start-Up Script[/h1]

To generate the configuration files we'll be needing to edit, we first need to start up Minecraft. Exciting, right? Let's do it properly, though. We'll make a file called [b]start.sh[/b] that we can use at any time to start the Minecraft server. That way we don't have to remember a long line of commands. So, let's create the file.

[CODE=bash]nano start.sh[/CODE]

This will open a screen with, what is essentially, a text editor. Now we just need to decide on something: RAM usage. Now the servers here at Ahoy World use 512MB to start up but have a limit of 2048MB (2GB). Setting it up like that causes a brief lag spike when the RAM usage goes up to the limit, but then it's stable and doesn't have to be running at that level all the time. For now, let's assign 512MB minimum and 1024MB maximum. This is done with the [b]-Xms###M[/b] and [b]-Xmx###M[/b] flags. Let's type this into our text editor, substituting [b]minecraft_server.jar[/b] for [b]craftbukkit.jar[/b] if you downloaded Bukkit:

[CODE=bash]screen -dmS Minecraft java -Xms512M -Xmx1024M -jar minecraft_server.jar nogui[/CODE]

Now press [b]CTRL+X[/b] to start exiting the program. It'll ask if you want to save at the bottom - just press [b]Y[/b] and you're done.

Now that we've created our start-up file, we'll quickly need to make it executable so we can use it. To do so, type the following command:

[CODE=bash]chmod +x start.sh[/CODE]

Brilliant! Now at any time we can type [b]./start.sh[/b] and our Minecraft server will start! Don't do it yet though.

[h1]First Start-Up[/h1]

Let's start up Minecraft for the first time, generate some config files and then stop it so we can edit them. Using part of the code we typed into [b]start.sh[/b], type the following into the terminal, again substituting [b]minecraft_server.jar[/b] for [b]craftbukkit.jar[/b] if you downloaded Bukkit:

[CODE=bash]java -Xms512M -Xmx512M -jar minecraft_server.jar nogui[/CODE]

That should've started up the Minecraft server and made the terminal stream some data. Let it create all the config files for the first time, along with the map. When it says [b]Done[/b] on the last line and stops, simply type [b]stop[/b], press enter and we'll edit some files.

[h1]Configuring the Server and Forwarding Ports[/h1]

Minecraft's configuration is really, really easy. It's all sorted into one file for you and nicely laid out with a bunch of user-friendly options. Let's open up the [b]server.properties[/b] file that Minecraft has created and edit it. Type:

[CODE=bash]nano server.properties[/CODE]

Now we're editing the file! As you can see, it's pretty simple; just a bunch of variables and their values. Here's a couple that should be noted:

  1. [b]server-ip[/b] controls what IP address the server will use to accept connections. Unless you have a server with more than one [i]external[/i] IP address, leave this as [b][/b]. Changing it could cause you issues
  2. [b]server-port[/b] is the port number that Minecraft will bind to and use to accept connections. Everything uses port numbers - if a web server is accessed it'll be accessed through port 80. ArmA II uses port 2302 to accept connections, FTP is 20 and 21, SSH is 22 etc. [b]25565[/b] is the default and means that people won't need to specify the port number when connecting to the server. You only really need to fiddle with this if you have more than one Minecraft server running.
  3. [b]view-distance[/b] can be heavy on resources. Most servers use a view distance of [b]10[/b], though I'd recommend setting it to [b]5[/b] if you're running your server with or less than 1.5GB of RAM.

When you're done editing, just save and exit the program like last time ([b]CTRL + X[/b] followed by [b]Y[/b]).

Now a very common problem is people not being able to connect to their Minecraft server as the port is blocked by their firewall. While I can't cover port forwarding every router (try a website like PortForward.com), I can show you how to accept connections from the [b]25565[/b] port in Linux. We'll use [b]iptables[/b]. Use the following command to accept [b]TCP[/b] connections to the [b]25565[/b] port (make sure you're logged into an administrative / root account when you do this):

[CODE=bash]sudo iptables -A INPUT -p tcp --dport 25565 -j ACCEPT[/CODE]

That should do the trick.

[h1]Starting the Server and Using Screen[/h1]

Let's fire 'er up! Type [b]./start.sh[/b] and the server will start in the background using [b]Screen[/b]. As mentioned above, Screen allows us to run applications in the background as if they're just on another monitor. Let's go to the Minecraft screen right now. Type:

[CODE=bash]screen -r Minecraft[/CODE]

You should now go to a new screen where Minecraft is running! Fantastic! Type [b]help[/b] to get a list of commands you can use to administrate your server! If you ever want to stop your Minecraft server, connect to the screen using my above command and then type [b]stop[/b]. This allows Minecraft to save all block changes and the like before it shuts down so nothing is lost.

To get out of the screen and leave it be, press [b]CTRL+A[/b] and then [b]D[/b]. Not [b]CTRL+A+D[/b] - press [b]CTRL+A[/b], let go and then press [b]D[/b]. This will detach you from the screen and leave Minecraft running!


Hoorah! We're done! Use the IP address of your server to connect and go!

That should be everything. Any questions, just ask.

Link to comment
Share on other sites

  • 4 months later...

Hey, Love your site! Great!

Question! Am I doing something wrong? Or is the link good? I can download the same link from a browser on my mac just fine"

wget https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar

it is giving me a log in error.. "of course I am under the user minecraft at the time"

Any advice I would be thankful!

Link to comment
Share on other sites

Hey thanks for your help, I got past that part.. but I do get another error when it installs the java in the beginning.

here is a paste of the error.. is this going to hurt me?

Any advice would be great..


Login@myserver sudo ./oab-java.sh
oab-java.sh v0.2.3 - Create a local 'apt' repository for Sun Java 6 and/or Oracle Java 7 packages.
Copyright (c) Martin Wimpress, http://flexion.org. MIT License

By running this script to download Java you acknowledge that you have
read and accepted the terms of the Oracle end user license agreement.

* http://www.oracle.com/technetwork/java/javase/terms/license/

If you want to see what this is script is doing while it is running then execute
the following from another shell:

tail -f /home/demo/oab-java.sh.log

[x] Installing Java build requirements success
[x] Making build directories success
[x] Removing clones of http://github.com/rraptorr/sun-java6 success
[x] Cloning http://github.com/rraptorr/sun-java6 success
[x] Checking out v6.38-1 success
[x] Getting Java SE download page success
[x] Getting previous releases download page success
[x] Downloading jdk-6u38-linux-i586.bin : failed
Showing the last 5 lines from the logfile (/home/demo/oab-java.sh.log)...
4218's retcode: 0
[x] Downloading jdk-6u38-linux-i586.bin : http://: Invalid host name.
4237's retcode: 1


I found the issue, the java file had been updated from V0.2.3 to v 0.2.6

like this



wget https://github.com/flexiondotorg/oab-java6/raw/0.2.6/oab-java.sh -O oab-java.sh


That worked for me.

Link to comment
Share on other sites

When you're running the wget command are you logged in as SU? if not try the same command but as


sudo wget https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar


Hey thanks, I was able to get it downloaded.

How I did it was, I had to add the user minecraft to the sudo user group .. by this command


(and then add minecraft to the sudo group to look like this)

# Allow members of group sudo to execute any command
%minecraft ALL=(ALL:ALL) ALL

saved and exit out

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Forum Statistics

    Total Topics
    Total Posts
  • Create New...