Blog


So I finally gave in and joined the craze that is Minecraft. It is a highly addictive game, so I would highly recommend against playing it while you have stuff to do, though you get 25% off while it is in beta, so go buy it (not an affiliate link, just love the game). A couple people that I work with love the game, and I love servers, so I figured we should set up our own server! I grabbed some hardware (A Dell GX620 with a Pentium D and 4GB of RAM), and got started. Here’s how you can set up your own server, along with some tips I’ve found to make life much easier.

Considerations

Before you set up a server, you need to consider a few things, and decide whether it is worth it to host it in your house or just rent one from one of the many places selling Minecraft hosting.

  1. Power – This server probably needs to be on 24/7, and will use a lot of power. You might be able to get away with a smaller, Intel Atom based server, such as one by SuperMicro, which will use less power, but won’t be able to host as many people. I’d assume at least 10 people could be simultaneously hosted on a single core Atom without too much trouble. Also, power costs money, so figure out how much money you’ll be spending.
  2. Heat – I have mine in a closet, which is not ideal. The closet is right next to an air conditioner, so that works, but the closet is still really hot and is probably shortening the life span of this and the other servers.
  3. Internet Connection – Research online shows each player probably uses about 20Kb/s. So take about 80% of your upload (not download) speeds, and divide by number of players. You may want to lower the number of players a bit, since each player loads the whole map when they connect, which will use more bandwidth ideally, to allow users to log in quickly.
  4. RAM – each user will probably use about 64MB of RAM. The system itself will use anywhere around 100MB, but should have room to grow a bit.

If you’re OK with all this, move on!

Installation

Go grab a Ubuntu server image (I’m using 10.04 x64, since it will be supported until 2013), and burn it to CD. Boot off it, and do a default configuration, making sure to check OpenSSH server at the end.

First off, we are going to create a Minecraft user. This will allow us to always connect as that user, and have our own user account. This command will create a new user with a home directory. Then we’ll add a password so we can ssh in as them.

sudo useradd -s /bin/bash -m -U minecraft
sudo passwd minecraft
sudo adduser minecraft admin

Now we need to get the prerequisite software for Minecraft, namely, Java.

# Run updates
sudo apt-get -y -q update && sudo apt-get -y -q upgrade
# Get some software so we can add the repository with Java in it, then update again
sudo apt-get install python-software-properties
sudo apt-get -y -q update
# Add the repository with Java in it, then update to get a list of packages
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get -y -q update
# Finally, install Java!
sudo apt-get -y install sun-java6-jre sun-java6-plugin
sudo update-alternatives --config java
# Finally, we will need the screen software later
sudo apt-get -q -y install screen

Now we will log in as the minecraft user and install the server software

su minecraft
cd /home/minecraft
mkdir minecraft-server
cd minecraft-server
# Go to http://www.minecraft.net/download.jsp, right click "minecraft_server.jar", and copy link address, and replace the URL to get the latest version
wget http://www.minecraft.net/download/minecraft_server.jar?v=1307640603925
# We will need this later. Keep track of the number starting with 192.
ifconfig  | grep 'inet addr:'

Now we are going to add some commands that will make our lives as Mincraft server admins easier.

# As minecraft user
nano ~/.bash_aliases
----
# Add these lines
alias startmc="screen -dmSL minecraft java -Xms1024M -Xmx1024M -jar /home/minecraft/minecraft-server/minecraft_server.jar nogui"
alias mcconsole="screen -d -r minecraft"
alias mclog="less /home/minecraft/minecraft-server/server.log"
# Type ctrl + X then y to save and exit nano

# To load these new settings, we need to reload bash.
bash

# And the aliases should be working now!

These commands use a program called screen. Basically, if you were to just run the java command they have on the wiki, the server would run only as long as you were connected to the server (and later I’ll show you how to connect via SSH, where you wouldn’t want that connected all the time). This way, it is run in its own process and not tied to the terminal you have open. The console command simply attaches the screen to your current terminal.

Now, these three commands should be available at the terminal. So type “startmc” to start a Minecraft server inside of a screen (so you can connect to it later). “mcconsole” will bring up the Minecraft console for you to command. Hit Ctrl+a then d will detach the screen, and put you back at the normal command line. “mclog” will display the server logs, so you can read through.

Make It Public

What good is a server if only you can access it? Boo! This is going to be general, because I can’t cover every possible router in the world. Grab that number that you kept track of, which is your machine’s IP address. Log into your router, and look for NAT or Port Fowarding. Set up a port forward on port 22 to port 22 on the IP address you wrote down. This will allow us to log in and manage the server from anywhere. Also, we need to forward port 25565 to that IP address also.

If your router supports a dynamic DNS name, I would highly recommend setting that up, probably through DynDns.org. This way your users can connect to a domain name like minecraft.example.com, rather than an IP address, which may change, depending on your ISP. To get your public IP address, simply visit http://www.whatismyip.com/.

Connecting To It

If you want to connect for gaming, simply fire up Minecraft and type in either your public IP address, or the dynamic domain name you set up. If you want to connect via SSH to manage the server, either use SSH (Linux/Mac), or download Putty. Simply connect to your public IP or your dynamic DNS name, and run “mcconsole” to get to the console.

Alternate: Run on EC2

A commenter on reddit mentioned that running this on EC2 may be a more economical approach. If you don’t have an EC2 account already, you can get some of the resources for free for a year by using a tiny instance. I haven’t tested this yet, and I am curious how the performance would be, since the CPU for a tiny instance is smaller than the others and burstable. Also, you will be charged for the bandwidth over 15GB in or out, however I don’t think many people will likely hit that amount in a month. Plus, this way frees you up from paying for the power, and keeps your home internet speedy.

Conclusion

I hope this worked for you. If it didn’t, post a note in the comments and I will try to help you. If it did, post that too!! I like knowing that I’m helping. If you have suggestions, please post those so everyone can run this awesome game better. I’ll be writing up another article in a few days (hopefully) about some more advanced ways to manage your server, including posting messages and server status to Facebook/Twitter automagically.



About Josh Gachnang

Josh Gachnang is a small business consultant with 5 years of experience in developing IT systems. His specialties include moving IT infrastructure to the cloud, standard and mobile web development using Python and Django, and promoting with social media.  ,

49 Comment(s)
  1. Pingback: Minecraft Server on Ubuntu « Linux « Technology « Theory Report

  2. Gerriet June 11, 2011 at 9:48 am

    Wow, great tutorial .. thanks for that ;D

  3. Rovanion June 11, 2011 at 4:49 pm

    I would recommend using this init-script for starting Minecraft: https://github.com/Ahtenus/minecraft-init/blob/master/minecraft

    We have tried different optimizations and this is the best configuration that we’ve come up with. It minimizes Harddrive usage which is the primary reason for slowdowns on Minecraft servers. It utilizes ramdisks heavily, does backups and log archival (It’s crazy how much the log slows down the server!).

    • Josh Gachnang June 11, 2011 at 5:01 pm

      Looks like a really good script! I’ll start toying with that on my Dev server. I’m writing a few other scripts for it right now. Thanks :D .

  4. mike June 12, 2011 at 3:23 pm

    im followingyour tutorial which is great btw….. every single step yet i come across this error with step number 5 minecraft@minecraft:~/minecraft-server$ mcconsole
    Cannot open your terminal ‘/dev/pts/2′ – please check.

    • Josh Gachnang June 12, 2011 at 6:37 pm

      A couple of things could be wrong here. It sounds like you have the alias set up correctly. It sounds like you don’t have permissions to that pseudo terminal. First try logging out and logging directly in as the minecraft user. Hopefully that should work. Otherwise you can try “sudo chmod o+rw /dev/pts/2″, however this is insecure (giving everyone on the system access to that terminal).

  5. matt mosner June 26, 2011 at 1:01 am

    when i try the mcconsole command it says that there is not screen to be detached.

    • Josh Gachnang June 26, 2011 at 10:38 am

      Run “screen -ls” to list the available screen. Try “screen -r” to just reconnect to the only available screen. Are you logged in as the minecraft user?

  6. Doug June 28, 2011 at 3:28 pm

    I followed our guide but when I start a screen as the minecraft user and then put in bash, and try the command “startmc” it says

    minecraft@media:~$ startmc
    bash: startmc: command not found
    minecraft@media:~$

    I edited the aliases file? do I need to reboot the server to make it work?

    • Josh Gachnang June 28, 2011 at 3:34 pm

      It sounds like you have reloaded the bash profiles. Simply type “bash” into the terminal, and it’ll reload the aliases and other bash settings. That sentence was hidden a couple paragraphs down. I’ll move it up a bit. Hope it works!

      • Doug June 28, 2011 at 3:41 pm

        Hmm, well it’s still doing that. I typed exit a few times to get back to the main terminal screen and then typed

        minecraft@media:~$ bash
        minecraft@media:~$ startmc
        bash: startmc: command not found
        minecraft@media:~$

        • Josh Gachnang June 28, 2011 at 3:43 pm

          Could you try a “cat /home/minecraft/.bash_aliases” and post that? Are you using Ubuntu 10.04?

  7. Doug June 28, 2011 at 3:47 pm

    I think it was the last LTS build. Which seems to be 8.04.4 hardy.

    minecraft@media:~/minecraft-server$ cat /home/minecraft/.bash_aliases
    alias startmc=”screen -dmSL minecraft java -Xms1024M -Xmx1024M -jar
    /home/minecraft/minecraft-server/minecraft_server.jar nogui”

    alias mcconsole=”screen -d -r minecraft”

    alias mclog=”less /home/minecraft/minecraft-server/server.log”

    • Doug June 28, 2011 at 3:47 pm

      By the way this is my dedicated home server which basically hosts files for the entire house, which is why it doesn’t get upgraded very often. It’s running ubuntu server edition 8.04

    • Josh Gachnang June 28, 2011 at 3:52 pm

      Hmm that’s odd! I understand not upgrading :D And 8.04 is supported for another 2 years, so no problem. It is possible that your ~/.bashrc isn’t loading the ~/.bash_aliases file (I don’t know when they added that). Try dumping all the aliases at the end of your ~/.bashrc file (make a backup, just in case!), and then reload bash.

      To check if it is loading ~/.bash_aliases, look for these lines:

      if [ -f ~/.bash_aliases ]; then
      . ~/.bash_aliases
      fi

      Good luck!

      • Doug June 28, 2011 at 3:58 pm

        Ok, that stuff is in that file, but it’s commented out, so I guess I need to uncomment them.

        • Doug June 28, 2011 at 3:59 pm

          There we go! lol, now I get permission denied…… herm

          minecraft@media:~$ bash
          minecraft@media:~$ startmc
          bash: /home/minecraft/minecraft-server/minecraft_server.jar: Permission denied
          minecraft@media:~$

          • Josh Gachnang June 28, 2011 at 4:13 pm

            Glad that worked :D

            Check the file permissions with an “ls -l” in the ~/minecraft-server/ directory. They should either have something like “minecraft minecraft” or possibly “root root”. If it is the latter, you could try “sudo chown minecraft /home/minecraft/minecraft-server/minecraft_server.jar”. If there is a lot of stuff owned by root, you might be better off by doing a “sudo chown -R minecraft /home/minecraft/minecraft-server” to make sure you own everything in the minecraft server directory.

  8. Doug June 28, 2011 at 4:24 pm

    Well… even after trying to change the owner it still shows this

    minecraft@media:~/minecraft-server$ ls -l
    total 481
    -rw-r–r– 1 minecraft minecraft 491437 2011-05-31 08:40 minecraft_server.jar

    Which I believe that’s root root.

    • Josh Gachnang June 28, 2011 at 4:37 pm

      Well first let’s try just running the command without all the (usually) helpful aliases.

      Just try “java -Xms1024M -Xmx1024M -jar /home/minecraft/minecraft-server/minecraft_server.jar nogui” as the minecraft user. If that fails, try “sudo java -Xms1024M -Xmx1024M -jar /home/minecraft/minecraft-server/minecraft_server.jar nogui”. If that fails, we’ve got a serious problem..If either works though, try:

      “screen -dmSL minecraft java -Xms1024M -Xmx1024M -jar /home/minecraft/minecraft-server/minecraft_server.jar nogui”. If that fails, we’ve got some weird screen issue. If the previous one fails, just for completeness, try “sudo screen -dmSL minecraft java -Xms1024M -Xmx1024M -jar /home/minecraft/minecraft-server/minecraft_server.jar nogui”.

      Also, maybe you’re inside a screen right now? Try logging out and logging back in, or just open a new terminal window if you’re at the machine.

      • Doug June 28, 2011 at 4:42 pm

        Ok, first command works, the screen command without sudo has no output? I’m SSH’d in as the server is headless.

        • Doug June 28, 2011 at 8:18 pm

          Well the server is running for now I guess, people can connect and everything I just can’t get those quick commands to work for some reason. Let me know if you have any idea why permissions would be denied for the alias’s but not if I do them my self….

        • Josh Gachnang June 28, 2011 at 8:32 pm

          Well that is very, very odd. It sounds like the screen program is different in 8.04, but I can’t figure out why. If I get some time tomorrow, I will install 8.04 in a virtual machine and see if I can’t figure it out.
          It seems the only real problem you’re having is with screen for some reason. The alternative I’d recommend (and will be doing a new article with shortly) is TMux. It is generally the same as screen, but maybe you’ll have better luck with it. Google around for examples. I’m glad the server is running and people can play on it :D If you shut your SSH connection though, it will likely shut down the server (hence the need for screen/TMux).
          Thanks for your patience! Hopefully I’ll get you a better answer soon.

          • Doug June 28, 2011 at 8:43 pm

            Yeah I don’t mind leaving the SSH screen up for now. I’ll look for your new article and greatly appreciate the help! Thanks to you I also found out about dynamic DNS so that was nice lol.

  9. Taylor June 28, 2011 at 11:13 pm

    Thanks for the in-depth tutorial. I’ve been mulling over whether or not to set it up at home or purchase hosting as recommended here http://www.mods-for-minecraft.com/minecraft-server-hosting – But I decided to go with a VPS to host my Minecraft Server. Followed this tutorial and everything is running smoothly

    • Josh Gachnang June 29, 2011 at 1:15 pm

      I’m glad the tutorial worked for you! If I didn’t already have the machine and free electricity, a VPS would probably be my choice as well.

      • Doug June 29, 2011 at 11:36 pm

        My server is always on anyways and really is overpowered for what it normally does….I do believe I need a lot more memory though as I keep seeming to run out of memory for minecraft….. right now there is 3.5gb’s of memory reserved for the MC server which only leaves 500ish mb’s for the system. Going to have to upgrade.

  10. Doug July 7, 2011 at 12:47 pm

    I was curious if you ever got a chance to try and work out the script shortcuts in the LTS build? I’m sure you’re crazy busy so no pressure.

    • Josh Gachnang July 7, 2011 at 2:25 pm

      I am part way through the tutorial, assuming TMux will work better for 8.04. I hit a slight snag with one of the scripts, but I am working on it! :D Sorry for the delay!

      • Doug July 7, 2011 at 11:39 pm

        No worries man! Working fine for now other then I need to figure out this memory thing. Still giving me issues with 6gb’s dedicated to the MC server. Not sure if it’s a local issue with the client computer or if it’s a server issue? Oh well figure it out at some point.

        • Josh Gachnang July 8, 2011 at 11:21 am

          How many people are connected? I have at least 4 people running on mine (huge room to grow), with only 512MB dedicated to the server. I’m going to guess client issue. What client are you using?

          • Doug July 8, 2011 at 2:51 pm

            Yeah we have 4 tops. Umm we are all using the windows client on the desktop side. We’ve all gotten a “Out of memory” error and shutting down before damage is done or something of the sorts. We wanted to run the Canopy Carnage map but every time we do we get the message almost immediately after joining the game.

  11. Doug July 9, 2011 at 1:01 pm

    Seemed to of been a client issue as when I turned down the graphics settings it worked a lot better. Not sure why I’d be running out though? I have 2gb’s of video memory and 8gb’s of desktop memory.

  12. minecrafty August 1, 2011 at 8:35 pm

    Dang, great post…good read!

  13. Jon Jackson August 1, 2011 at 10:41 pm

    hmm i have to say that doing a server from my computer just wont cut it, now i use http://lockerhub.com/hosting/minecraft/ , they have a awesome connection, with more ram than i can spare on my home computer while i am playing.

  14. Josh August 2, 2011 at 3:50 pm

    Everything is working until I type in “mcconsole”, I get “There is no screen to be detached mathing minecraft”, I then typed “Screen -Ls” and then “Screen -r” like you said to do to the other guy but I got this: “minecraft@ubuntuServer:~$ mcconsole
    There is no screen to be detached matching minecraft.
    minecraft@ubuntuServer:~$ screen -Ls
    Use: screen [-opts] [cmd [args]]
    or: screen -r [host.tty]

    Options:
    -a Force all capabilities into each window’s termcap.
    -A -[r|R] Adapt all windows to the new display width & height.
    -c file Read configuration file instead of ‘.screenrc’.
    -d (-r) Detach the elsewhere running screen (and reattach here).
    -dmS name Start as daemon: Screen session in detached mode.
    -D (-r) Detach and logout remote (and reattach here).
    -D -RR Do whatever is needed to get a screen session.
    -e xy Change command characters.
    -f Flow control on, -fn = off, -fa = auto.
    -h lines Set the size of the scrollback history buffer.
    -i Interrupt output sooner when flow control is on.
    -l Login mode on (update /var/run/utmp), -ln = off.
    -list or -ls. Do nothing, just list our SockDir.
    -L Turn on output logging.
    -m ignore $STY variable, do create a new screen session.
    -O Choose optimal output rather than exact vt100 emulation.
    -p window Preselect the named window if it exists.
    -q Quiet startup. Exits with non-zero return code if unsuccessful.
    -r Reattach to a detached screen process.
    -R Reattach if possible, otherwise start a new session.
    -s shell Shell to execute rather than $SHELL.
    -S sockname Name this session .sockname instead of …
    -t title Set title. (window’s name).
    -T term Use term as $TERM for windows, rather than “screen”.
    -U Tell screen to use UTF-8 encoding.
    -v Print “Screen version 4.00.03jw4 (FAU) 2-May-06″.
    -wipe Do nothing, just clean up SockDir.
    -x Attach to a not detached screen. (Multi display mode).
    -X Execute as a screen command in the specified session.

    Error: Specify shell with -s
    minecraft@ubuntuServer:~$ screen -r
    There is a screen on:
    1148.pts-0.ubuntuServer (08/02/2011 01:46:33 PM) (Attached)
    There is no screen to be resumed.
    minecraft@ubuntuServer:~$ mcconsole
    There is no screen to be detached matching minecraft.
    minecraft@ubuntuServer:~$”

    • James August 11, 2011 at 3:57 am

      I am getting the same issue

      minecraft@datatank:~/minecraft-server$ mcconsole
      There is no screen to be detached matching minecraft.

      I can see the instance running when -ls:

      minecraft@datatank:~/minecraft-server$ screen -ls
      There is a screen on:
      1216.pts-0.datatank (08/11/2011 04:44:55 AM) (Attached)
      1 Socket in /var/run/screen/S-minecraft.

  15. Tyler September 14, 2011 at 4:51 pm

    Hey man, I followed everything step by step. However, when I went to log on, I tried to access server using this 192.168.2.1:25565 and it said can’t reach server. I have no clue what’s wrong

    • Josh Gachnang September 19, 2011 at 1:02 pm

      Are you logging in with the Minecraft client (I’m assuming)? Try dropping the port number and just use your IP.

  16. geoist November 2, 2011 at 3:02 am

    1.9 pre5 is working well on a mini instance of EC2.

    I’ve only been able to connect with 2 people. Can’t say it will run will on 512MB with more than 2 users.

    • Josh Gachnang November 4, 2011 at 12:41 pm

      Good to hear! I get 4 users on 1GB of RAM with no problems, so who knows how far it’ll go with a tiny instance.

  17. Pingback: Installing Minecraft On Ubuntu | Server Cobra

  18. David November 24, 2011 at 1:34 am

    I get an error when using the alias “startmc” it says “Unknown Option dmsl” any thoughts?

  19. Garfield0003 April 16, 2012 at 11:34 am

    Thank you for the guide. A couple of times the the guide itself was not as useful as looking through the comments, finding the fixes that were need. Many thanks.
    All I will ask, is how do you get it so you can run more than one server. I put up a temporary server for a community, but now I am hosting a lava survival server on the full game. I put in the new aliases, however when I did the equivalent of mcconsole, the old server was still there. How can I get it to come up on a separate screen. (Shows how much of a linux noob I am.) Thanks in advance for any help that is given =D

    • Josh Gachnang April 18, 2012 at 10:33 pm

      No problem! For the multiple servers, make sure you name each screen something different. And change the aliases to reflect that, such as “screen -d -r minecraft” changing to “screen -d -r lavasurvival” for mcconsole and startmc to “screen -dmSL lavasurvival java -Xms1024M -Xmx1024M -jar /home/minecraft/lavasurvival-server/minecraft_server.jar nogui”. If that doesn’t work, can you copy in the aliases you’ve added?

  20. guster11 April 16, 2012 at 11:32 pm

    Hey man, thanks a bunch for the tutorial. Everything has been working fine for me up until i had to add the java respository. Everything appears to be working fine then it stops and says it failed to fetch (url) “unable to find expected entry ‘partners/source/Sources’ in release file(wrong sources. list entry or malinformed file).

    Any idea on fixing this/new dl link? Thanks!

    • guster11 April 16, 2012 at 11:34 pm

      also under that is does mention some index files failed to download. They have been ignored, or old ones were used instead.

    • Josh Gachnang April 18, 2012 at 10:29 pm

      Which version of Ubuntu are you running?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>