Tutorials/Setting up a server

From Minecraft Wiki
< Tutorials(Redirected from Setting up a server)
Jump to: navigation, search

This tutorial takes you through the steps of setting up your own server—using the default server software that Mojang distributes free of charge. The software may be installed on most operating systems, including Windows, Mac and Linux.

Regardless of your operating system, you must begin by downloading the server software from Minecraft downloads page. It is recommended that you create a dedicated folder for the server files. (Ensure the filename is precisely minecraft_server.jar or minecraft_server.exe, in case your browser has renamed it to something else.)

Note: There is also custom server software available, but note that these applications are not supported by Mojang.

Contents

[edit] Windows Instructions

[edit] REQUIRED: Verify and Install the Latest Version of Java

  1. Make sure that you have Java 6 installed. Avoid Java 7 unless you are debugging it, or until sun have officially released it. To do so, we first need to open up a command (CMD) window.
    • In Windows Vista/7, open the start menu, enter cmd in the search field, and press enter.
    • In XP open the start menu and click Run, then enter cmd and press enter. You can also hold the Windows key down and press R to open Run.
    • At the command prompt, enter the following command, and
      press enter: java -version
    • Java then should display its version, which should read "Java version 1.6"
  2. If you get this error, "'Java' is not recognized as an internal or external command, operable program or batch file.", then you may have a previous version (less than 1.6) of Java or Java may not be in your system path.
    • For 32-bit users you can obtain the latest version here: Java download page. If you use a 64-bit OS ensure you download the Windows x64 package.
    • After you have installed the latest version of Java try again with java -version.
      If you get an error at this point, try the following to add Java to your system path.
      1. Right click Computer.
      2. Click properties.
      3. Click "Advanced system settings".
      4. Click "Environment Variables".
      5. Under system variables, find the Path variable.
      6. Click edit, and append to the end of the value: ;"c:\Program Files\Java\jre6\bin". If you use 32-bit Java on a 64-bit OS use: ;"c:\Program Files (x86)\Java\jre6\bin"
      7. Restart your computer.
      8. Now re-open the command prompt and try again.

[edit] Start the Minecraft Server (.exe version)

  1. Double click on the "Minecraft_Server.exe" file you downloaded and the server should start with a default configuration.
    • Upon its initial start, it may throw some "file not found" error messages. This is normal. The files are being created.
    • After the first start, you'll probably want to shut it down (enter stop in the server command window) and then edit some configuration files—as is explained below.

[edit] Increasing the amount of RAM allocated to the Minecraft server

If you would like to start your server with more RAM, you will need to create a Windows batch file and run your server that way. Don't worry, it's easier than it sounds.

  1. Open up Notepad (not Wordpad) to create a text document with no formatting (italics, boldface, etc.).
  2. Identify your Windows OS type (32-bit or 64-bit), which may be done through the Control Panel. Also, identify which version of Java you are running—32 bit or 64 bit.
  3. Based on your OS and Java types...
    1. If Windows is 32-bit or Windows is 64-bit with 64-bit Java, copy this into your document (on a single line) (adjust the following line for Java 6 if used):
      "C:\Program Files\Java\jre7\bin\javaw.exe" -Xmx2048M -Xms2048M -jar "Minecraft_Server.exe"
    2. If you are, for some crazy reason, running 32-bit Java on a 64-bit system, upgrade your Java. Also, if you have installed Java to a different directory or changed the name of your Minecraft server .exe file, see below.
    3. If you do have 32-bit Java on a 64-bit system, Java.com recognizes Java by browser, and some browsers are 32-bit, so downloading both 32-bit Java and 64-bit Java may be needed to run everything correctly
    • So what does all of this mean? The executable command ("C:\Program Files\Java\jre7\bin\javaw.exe") is the file path to the location of your most current javaw.exe file. If Java updates to Java 8, you will need to change 'jre7' to 'jre8'. If you installed Java to a different location, you will have to locate it and paste that file path in instead. The next part (-Xmx2048M -Xms2048M) is your RAM allocation, in megabytes (mb). By default, your server runs with about 100mb of RAM, which is very little. Most people will change their server to run on 1024mb (1Gb) of RAM and 2048mb of RAM (2Gb) is also common. As for the -jar, this indicates that Minecraft_Server.exe is a Java archive.
    • Lastly in the executable command is the name of our .exe file (Minecraft_Server.exe). Typically, it is named Minecraft_Server.exe. Upper and lower case does matter. Rename Minecraft_Server.exe to whatever you named your file. Then click File->Save As... and for the file name call it run.bat, and make sure you select *.* All File Types from the drop-down arrow. Then save it in the same location your server is saved, and double click your run.bat file. If all goes well, you will notice that you will have much more RAM free on your server!

If Windows does not recognize the filetype (You are being prompted to select a program to open it with), it may be because Minecraft_Server is missing the .exe extension. This can be fixed by renaming the Minecraft_Server file to Minecraft_Server.exe. If it worked, the icon should now be the Minecraft symbol.

If this does not work, you will have to go into a command window by opening Run, typing cmd and pressing enter. Once there you need to navigate to the folder you have created.

To do this:

  1. Ensure you are in the proper drive (usually C drive). Type C: and then hit enter to access the c drive
  2. Now you need to call the directory (open the folder). Type cd \"folder name" then hit enter. Make sure to include the quotation
  3. Ensure you are in the proper directory. Type dir and command will generate a list of contents of the folder, you should see minecraft_server there.
  4. Rename Minecraft. Type rename minecraft_server minecraft_server.exe then hit enter. This should add the .exe extension to the executable and it should now operate correctly

[edit] Start the Minecraft Server (.jar version)

  1. If you have the .jar version, you will need to have a path variable set up for Java in order to start the jar version of the server. Refer to step 3 of "Verify and Install the Latest Java" above to set up a path variable.
  2. To start the jar version of Minecraft on Windows, create a new file in Notepad, and paste in
    java -Xms512M -Xmx1024M -jar minecraft_server.jar
  3. Save the file as startserver.bat, and place the file in the same folder as minecraft_server.jar. The .bat extension saves the file as a batch file.
  4. Double click startserver.bat, and the Minecraft server will run.

[edit] Starting the jar version without altering your system path

To start minecraft.jar server without having to change your system path variable you need to instead express the path variable for Java in the "start.bat" file. This is handy because it allows you to still run commands from command prompt using the default system path, without having to constantly edit the system path.

  1. To do this open your start.bat file (or whatever you've named it) with Notepad
  2. On the very first line add the command
    @echo off
    so that a command window isn't opened to show the output from our start file
  3. On the next line, make sure the system can find Java (also called the Java Runtime Environment or JRE) by adding it to the Path Environment Variable. On a current Windows PC Java will be most commonly located at "C:\Program Files (x86)\Java\jre7\bin\java.exe", so what you would then write is
    path=%PATH%;%ProgramFiles(x86)%\Java\jre7\bin\java.exe
    where %PATH% contains the existing Path values and %ProgramFiles(x86)% contains the location of your 32bit Program Files - usually "C:\Program Files (x86)" (adjust this if you are using Java 6)
  4. Finally, make sure on the last line you have the command that starts the Minecraft server itself:
    java -Xms512M -Xmx1024M -jar minecraft_server.jar
  5. If you prefer not to use the server's Graphical User Interface (GUI) to enter administration commands, simply add the option nogui to the end of the last command above, so that it reads:
    java -Xms512M -Xmx1024M -jar minecraft_server.jar nogui

[edit] Mac OS X Instructions

Setting a server up in Mac OS X is "more involved" than in Windows because an executable file has not been made available. A video tutorial of the process can be seen here. Keep in mind that the server won't run correctly on OSX 10.4 and may crash your machine.

[edit] Downloading

Ensure you have the latest server application software. Look above for instructions.

[edit] Installing Java

Mac OS X already comes with its own version of Java that is updated automatically via Software Update (Apple menu > Software Update).


[edit] Setting up the Minecraft Server

Ensure you have followed the download step before proceeding.

#!/bin/bash
cd "$(dirname "$0")"
exec java -Xmx1G -Xms1G -jar minecraft_server.jar

[edit] Run as a daemon

Alternatively you can automate the startup of the Minecraft server.

Create a Mac OS X startup daemon

[edit] Linux Instructions

This tutorial for how to set up a Minecraft server on Linux was designed for people who don't have a lot of experience with Linux. There is a more advanced tutorial in the forums. This tutorial was tested on Ubuntu 9.10 32-bit but should work with the descendants of Debian.

[edit] Downloading

Ensure you have the latest server application software. Look above for instructions.

[edit] Installing Java

If you get java: command not found (which may be followed by more text) or if you do have another Java version than 1.6 then you need to install or update java. The official Sun Java is recommended. Quite a few individuals have experienced issues with OpenJDK. If OpenJDK is installed, remove it before installing the official Sun Java.

[edit] Debian

Ensure that the non-free repository is being scanned by apt. You do this by adding non-free to your /etc/apt/sources.list file. e.g.:

deb http://ftp.uk.debian.org/debian/ squeeze main non-free

Update your sources list: apt-get update as root

Then to install Java, simply type this in terminal and press enter: apt-get install sun-java6-jre as root

[edit] Ubuntu

For Ubuntu 10.04 LTS and on, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. You must add these sources:

sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"

sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"

Some distros have the command "add-apt-repository" removed. If this is the case, you will need to add the python properties by running the following command:
sudo apt-get install python-software-properties
Then you can proceed to add the source:
sudo add-apt-repository "deb http://archive.canonical.com/ubuntu natty partner"

sudo add-apt-repository ppa:ferramroberto/java

sudo apt-get update
sudo apt-get install sun-java6-jre
sudo update-alternatives --config java

[edit] openSUSE

Use zypper in java-1_6_0-sun

[edit] Arch Linux

Open a terminal and run pacman -Syu openjdk6 as root.

[edit] Gentoo

Use emerge virtual/jre

[edit] Other Distros

Alternatively, you can visit Java's website directly to download the Java package for Linux. Most distros work with this (either 32 or 64-bit). Instructions for the installation of those different packages are given on the site.

If during installation, it asks for a password, enter your password. If you get asked "Is this OK [Y/N]" Enter Y and press enter if required. Java should now be installed.

[edit] Start the Minecraft server

Open the terminal again Applications > Accessories > Terminal Enter the following commands, substituting 'minecraft_server' with the name of the folder you extracted the server to:

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

[edit] Less than 1GB free RAM

If you have less than 1024MB RAM, the above line may cause problems with swapping and out of memory conditions, which makes the game hard to play.

cd 'minecraft_server'
java -Xms1024M -Xmx1024M -jar minecraft_server.jar nogui
free -m
It may look like this:

Ram left.PNG

You are interested in the last number in the third line, 2163 in this case. Subtract some RAM as safety. On this computer, the server may use up to 1536 MB RAM. Now, replace the 1024 in the above example with the calculated number:

java -Xms1536M -Xmx1536M -jar minecraft_server.jar nogui

Voila, it should run smoothly now

Tip: If you want to spare more memory, you may set the -Xms parameter even lower, say:

java -Xms32M -Xmx512M -jar minecraft_server.jar nogui

The parameter controls how much memory is reserved on startup Your server will start with 32MB RAM and whenever it needs more memory it will allocate some until it reaches the maximum of 512 MB. However, this will result in a little slowdown whenever the allocation is done.

[edit] Startup and maintenance script

Alternatively you can automate the startup of the Minecraft server.

Server startup script

M3tal_Warrior Server Startup Script

[edit] Configure and connect

Now it is time to configure and connect.

[edit] Configuring the Minecraft Server

  1. Configure the server by editing the server.properties file, the format for which is explained here. Be certain to edit the file with a text editor that does not add formatting (e.g., for italics). Additional configuration may not be necessary as many servers run fine from the default values.
  2. Add your username to the admin.txt and/or ops.txt (newer Minecraft versions may not have an admin.txt file).
    • Ops.txt and admin.txt determine who may execute server commands. In other words, operator ("op") privileges allow you to control certain aspects of the game (e.g., teleporting players).
    • Op privileges may also be granted from the server GUI: type "op <username>" and it will automatically add <username> to the ops.txt file.

[edit] Connect to the Minecraft Server

[edit] IP address notes

[edit] Firewalling, NATs and external IP addresses

[edit] Local Network Dedicated Servers

This only applies to Classic (v0.30) servers.

A common problem for server administrators is the inability to connect to your own server via another machine on your local network. A typical scenario for this is that you have a Classic server running on a dedicated machine, and you have your own machine which you play on. They're both connected to the same router/switch, and have internal IP's with the octets '192.168.x.x'. Normally, connecting via the URL generated for your server will result in an error message claiming that the server is offline.

To correct this, you must add a function to the end of your URL, bookmarks, or whatever else you connect by. The function is: ?override=true
Example: http://www.minecraft.net/classic/play/4c3bebb1a01816acbe31c5ece1570da5?override=true

Previously, (before the 1.8 beta and website update) this was &override=true. This caused much confusion since the change was not announced by Mojang, and wasn't announced on the website applet pages either. Before the update, connecting to your own URL via the website resulted in red text under the applet window saying "If you can't connect, try this link instead." The link returned the same thing, with the &override=true affixed to the end.

Note: This situation does not effect Beta servers, and you should be able to connect via an internal or external IP.

[edit] Setting Up a VPN (Hamachi)

An easy way to set up a server between you and your friends is to set up a VPN (virtual private network). A free software utility that can be used to set this up is Hamachi by LogMeIn. Don't use this for public servers. Many users will not take the extra time to install the client and such.

Advantage of doing this saves you configuring ports on your router and if you have a dynamic IP address using Hamachi will provide you with a static IP.

  1. Install software on you and your friend's computers https://secure.logmein.com/products/hamachi2/ or https://secure.logmein.com/US/labs/?wt.ac=73-516-440 for Linux (32-bit and 64-bit .deb and .rpm packages are available, you can install it on Gentoo by emerging "net-misc/logmein-hamachi")
  2. One person sign up for admin via logmein website
  3. Create new network
  4. Pass these details onto every person concerned and get them to login
  5. One person set up a server.
  6. Everyone else connect via their Hamachi ip address and use port number 25565 (default)

[edit] FAQ (Frequently Asked Questions)

Q: When I try to connect to my server this is what it says:

                       Connection lost 
        The server responded with an invalid server key

A: Wait a minute then try again. It should work, but if it doesn't connect within a few tries, you have a problem. Update the server to 1.0.1 (aka 1.1) (this should fix it)


Q: On a Windows computer, when I double click the batch file it opens a command prompt window, but quickly disappears and the server does not start. What should I do?

A: This is probably due to an incorrect path for javaw.exe. You may just need to change /jre7/ to /jre6/ . Or search your system for javaw.exe and adjust the path accordingly. (It's probably under c:\program files or c:\program files (x86).) Also, you must have the offline version of Java installed—not just the Java plug-in for your browser.


Q:whenever i try to get the server up, it says "Failed to Bind to Port."

A: This usually means that Port Forwarding/Triggering is not configured correctly on your router. Check your routers manual and make sure the port for Minecraft (Default is 25565) is forwarded to the internal IP address of your server. If your server is not behind a router then check with your ISP to see if that port is available for use and if not try a different port by changing it in your server.properties file in this line: server-port=25565.

Note: You should not use the following ports for your server as most ISP's block these ports for security reasons:

Generally avoid any port below number 1024, since those ports are generally referred as well-known ports and are registered with the IANA for important services.


Q: I tried to run the server with Solaris/OpenSolaris and got the following error:

java.io.InterruptedIOException: Operation interrupted 
at java.net.SocketInputStream.socketRead0(Native Method) 
at java.net.SocketInputStream.read(SocketInputStream.java:129) 
at java.net.SocketInputStream.read(SocketInputStream.java:182) 
at java.io.FilterInputStream.read(FilterInputStream.java:66) 
at gq.a(SourceFile:131) 
at ji.g(SourceFile:197) 
at ji.c(SourceFile:17) 
at oq.run(SourceFile:84) 
2011-05-31 16:57:26 [INFO] /:44673 lost connection

A: For whatever reason, out of all of the operating systems, only Solaris throws that exception when a thread interrupts a connection. A workaround is to change the default behaviour on the command line:

java -Xmx1024M -Xms32M -XX:-UseVMInterruptibleIO -XX:+UseConcMarkSweepGC \
 -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts\
 -jar minecraft.jar nogui

This instructs Java to use an interruptible IO stack instead of the default IO that is sensitive to interrupted threads.


Q: I cannot break/place any blocks!?

A: Walk away from your spawn area. You cannot break or place blocks near spawn (unless you are operator on the server).


Q: My server runs fine but I cannot connect to it!

A: Your server may be running with the IPv6 stack.

You can check this in linux by running netstat -ln | grep 25565 where 25565 is the port your server is running on. If a line is returned with tcp6 then you need to add -Djava.net.preferIPv4Stack=true to the startup parameters. Example:

java -Xmx1024M -Xms1024M -Djava.net.preferIPv4Stack=true -jar minecraft_server.jar nogui

---

Q: How do you give a .jar server more ram?

A: Change the numbers in the server launch command "-Xmx1024M -Xms1024M". The -Xms part specifies how much memory the server starts with, and the -Xmx part is the maximum amount of memory the server can use. Values are in megabytes.

[edit] Other Tutorials

Here are some other tutorials on how to set up a Minecraft server.

Personal tools
Namespaces
Variants
Actions
Minecraft Wiki
Minecraft
Toolbox
In other languages

Recent Community Articles

Mojang Tweets

    Getting your tweets...