Setting up a Minecraft server on Compute Engine

This tutorial is not approved by or associated with Mojang or Minecraft.

To run a dedicated Minecraft server, you need to have a dedicated server machine, plenty of RAM, and plenty of bandwidth. Why not let Google handle these requirements for you? In this tutorial, you'll learn how to install, configure, and run a standard Java Minecraft server on Compute Engine. This server is compatible with standard Java-based desktop Minecraft clients.

Your Minecraft server software will run on a Compute Engine instance, which is a virtual machine that runs on Google's infrastructure. This tutorial uses the default machine type for Compute Engine instances, n1-standard-1. The n1-standard-1 machine type includes a 10 GB boot disk, 1 virtual CPU (vCPU), and 3.75 GB of RAM. This machine type runs Debian Linux by default.

To make sure there's plenty of room for your Minecraft server's world data, you'll also attach a high performance 50 GB persistent solid-state drive (SSD) to your instance. With the addition of this persistent SSD, your instance will satisfy the system requirements for a dedicated Minecraft server, supporting up to 50 players comfortably.


  • Create a Compute Engine virtual machine instance
  • Install and configure the Minecraft server
  • Set up automatic backups of your Minecraft world data


This tutorial uses the following billable components of Google Cloud:

  • Compute Engine virtual machines
  • Compute Engine persistent disks
  • Cloud Storage

To generate a cost estimate based on your projected usage, use the pricing calculator. New Google Cloud users might be eligible for a free trial.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

Create and configure your Compute Engine instance

Start by creating and configuring a new Compute Engine instance.

  1. In the Cloud Console, go to the VM instances page:

    Go to the VM instances page

    You'll arrive at a dialog prompting you to create a new Compute Engine instance.

  2. Click Create to get started.

  3. On the Create an instance page, configure your instance as follows:

    • Name your instance. This tutorial uses the instance name mc-server throughout.
    • Select the region and zone in which you want your instance to be hosted. This tutorial uses the region us-central1 (Iowa) and the zone us-central1-f throughout.
    • In the Boot disk section, click Change. The Boot disk dialog will pop up.
    • Change the disk type to SSD Persistent Disk.
  4. Click Select to commit the change and close the dialog.

That's it for basic configuration! But don't create your new instance just yet. To meet the requirements for a dedicated Minecraft server, you'll need to configure some advanced settings as well.

Enable Cloud Storage access for your instance

Later in this tutorial, you'll learn how to back up your world data to Cloud Storage, which requires your instance to have read and write access to Cloud Storage. To enable access:

  1. Under Identity and API access, click the Service account dropdown and select Compute Engine default service account.
  2. Set Access scopes to Set access for each API.
  3. In the Storage dropdown, select Read Write.

Tag your instance

Next, tag your instance. Later in the tutorial, you'll use this tag to create a firewall rule that will allow external Minecraft clients to access your server.

  1. Click Management, security, disks, networking, sole tenancy to reveal a set of tabs for advanced settings.
  2. In the Networking tab, add the tag minecraft-server to the Network tags field.

Set up a static IP address for your instance

To be able to forward incoming requests to your instance dependably, your instance will need to have a static IP address. To add a static IP address to your instance:

  1. In the Networking tab, in the Network interfaces section, click Default. The Network interface configuration menu appears.
  2. Click the External IP dropdown and select Create IP address. A dialog pops up:

    Create a new static IP address

  3. Name your IP address mcs-ip.

  4. Click Reserve to create the address.

  5. Click Done to commit your changes and close the Network interface configuration menu.

Add a persistent disk to your instance

Next, you'll attach a persistent disk to your instance. Unlike boot disks, persistent disks are not tied to the life of your Compute Engine instance. For example, if your hosting needs change over time, you can move the disk to a more suitable machine type later.

The specific type of persistent disk you will use in this tutorial is a persistent SSD. This type of persistent disk supports very fast I/O operations, which can help reduce server lag.

To add a persistent disk to your instance:

  1. In the Disks tab, in the Additional disks section, click Add new disk. A disk creation dialog appears appears:

    Create a new disk

  2. In the dialog, fill out the form as follows:

    • Name: minecraft-disk
    • Disk type: SSD Persistent Disk
    • Source type: Blank disk
    • Size (GB): 50
  3. Click Done. When you create the instance, the disk will be created and attached automatically.

Create your instance

That's it for instance configuration! Click the Create button at the bottom of the page to create your new instance. This action will also take you back to the VM instances page.

Format and mount your persistent disk

At this point, your disk is attached to your instance, but it hasn't yet been mounted to the instance. That's okay—if you mounted the disk now, you wouldn't be able to do much with it. That's because, as with any disk, your persistent disk first needs to be formatted with a filesystem that your operating system—in this case, Debian Linux—can understand.

Begin by establishing an SSH connection with your instance. In the row for mc-server on your VM instances page, click SSH to open a browser-based SSH terminal:

SSH terminal

After your SSH terminal opens, create a new directory named minecraft in your instance's home directory:

user@mc-server: sudo mkdir -p /home/minecraft

You'll use this directory as a mount point for your persistent disk.

Next, format your disk:

user@mc-server: sudo mkfs.ext4 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/google-minecraft-disk

Finally, mount your disk:

user@mc-server: sudo mount -o discard,defaults /dev/disk/by-id/google-minecraft-disk /home/minecraft

Install and run the Minecraft server on your instance

Your persistent disk is officially mounted. Now it's time to do what you came here to do in the first place: install and run your Minecraft server.

Set up the Java Runtime Environment (JRE)

The Minecraft server runs on top of the Java Virtual Machine (JVM), so it requires the Java Runtime Environment (JRE) to run. Because the server doesn't need a graphical user interface, this tutorial uses the headless version of the JRE. This approach reduces the JRE's resource usage on your machine, helping ensure that the Minecraft server has plenty of room to expand its own resource usage if needed.

You'll need to update the Debian repositories on your Debian installation before you can download and install the headless version of the JRE. To do so, run the following command in your SSH terminal:

user@mc-server: sudo apt-get update

After your repositories are updated, you can install the headless JRE:

user@mc-server: sudo apt-get install -y default-jre-headless

Install the Minecraft server

Now that you've set up the JRE, it's time to download and install the Minecraft server. Begin by navigating to your minecraft directory:

user@mc-server: cd /home/minecraft

Because the minecraft directory contains your mounted persistent disk, you're going to need a special level of access known as root user access to run commands on it. Run the following to become the root user:

user@mc-server: sudo su

Next, download the current Minecraft server's Java archive file (JAR) to your instance. Visit the Minecraft download page, copy the file's URL from the download link, and then replace the URL in the following command with that URL.

root@mc-server: wget

Start the server for the first time:

root@mc-server: java -Xms1G -Xmx3G -d64 -jar server.jar nogui

The first run is a little anticlimactic: the server simply starts, reports some issues, and stops. If you run the following command, however, you'll notice that some new files have been created in the minecraft directory:

root@mc-server: ls -l

Among these new files, you'll find a file called eula.txt. Open this file for editing:

root@mc-server: nano eula.txt

This file contains a single boolean variable, eula. To use the Minecraft server, you must accept the terms of the Minecraft End User License Agreement (EULA). If you accept the terms of the EULA, set the value of eula from false to true, then save and exit.

Run the Minecraft server

If you start the Minecraft server again at this point, it will be tied to the life of your SSH session—that is, if you close your SSH terminal, the server will be terminated as well. To get around this issue, you can use screen, an application that allows you to create a virtual terminal that can be "detached," becoming a background process, or "reattached," becoming a foreground process. When a virtual terminal is detached to the background, it will run whether you are logged in or not.

In your SSH terminal, run the following to install screen:

root@mc-server: apt-get install -y screen

Next, start your Minecraft server in a screen virtual terminal. Use the -S flag to name your terminal mcs:

root@mc-server: screen -S mcs java -Xms1G -Xmx3G -d64 -jar server.jar nogui

Detach the screen terminal by pressing Ctrl + a, then typing d. The terminal will continue to run in the background. To reattach the terminal, run screen -r <terminal_name> as follows:

root@mc-server: screen -r mcs

Finally, detach your screen terminal again if needed. Type exit once to leave root user mode, then type exit again to close your SSH connection.

Congratulations! You now have a running Minecraft server. However, it's not quite ready to be shared just yet. Before you can share your server, you need to set up a firewall rule that will allow people to access it.

Allow clients to access the Minecraft server

To be able to forward incoming requests to your instance dependably, you'll need to create a firewall rule. To do so:

  1. In the Cloud Console, go to the Firewall page.

    Go to the Firewall page

  2. Click Create firewall rule.

  3. On the Create a firewall rule page, fill out the form as follows:

    • Name: minecraft-rule
    • Target tags: minecraft-server
    • Source filter: IP ranges
    • Source IP ranges:
    • Protocols or ports: Select tcp, and then enter port 25565 into the field provided.
  4. Click Create to create your new firewall rule. Users can now access your server from their local Minecraft clients.

Configure the Minecraft server

You might want to edit the server's default properties. To do so:

  1. Reattach the server's screen terminal.

    root@mc-server: screen -r mcs
  2. Enter /stop to stop the Minecraft server.

  3. Edit the file You can find information on each property type and its possible values on the page of the Minecraft Wiki.

    $ nano
  4. Restart the server.

    root@mc-server: screen -S mcs java -Xms1G -Xmx3G -d64 -jar server.jar nogui
  5. Detach the screen terminal.

Schedule regular backups

Whether you're running a local Minecraft client or running a Minecraft server, it's a good idea to back up your Minecraft world data on a regular basis. This section demonstrates how to set up regular backups of your world data using Cloud Storage.

Cloud Storage offers several different storage classes that are optimized for different use cases. This tutorial uses Standard Storage, which provides up to 5GB/month free of charge.

Create a backup script

Begin by establishing an SSH connection with your instance from the VM instances page in your Cloud Console. After the terminal opens, become the root user.

user@mc-server: sudo su

Create a new Cloud Storage Standard Storage bucket, replacing us-central1 with the Cloud Storage region closest to you and [PROJECT_ID] with your project ID. You'll use this bucket to store your backups.

root@mc-server: gsutil mb -c standard -l us-central1 gs://[PROJECT_ID]-minecraft-backup

Next, create a new shell script file,, in your minecraft folder, and open it for editing.

root@mc-server: nano /home/minecraft/

Paste the following script into the file. Replace [BUCKET_NAME] with your Cloud Storage bucket name:

screen -r mcs -X stuff '/save-all\n/save-off\n'
/usr/bin/gsutil cp -R ${BASH_SOURCE%/*}/world gs://[BUCKET_NAME]/$(date "+%Y%m%d-%H%M%S")-world
screen -r mcs -X stuff '/save-on\n'

This script begins by saving the current state of your world data and pausing your server's auto-save functionality. Next, the script backs up your server's world data directory (world), placing its contents in a timestamped directory ([TIMESTAMP]-world) in your Cloud Storage bucket. After the script finishes backing up the data, it resumes auto-saving on the Minecraft server.

Save and exit, then run the following to make your script executable:

root@mc-server: chmod 755 /home/minecraft/

Test the script:

root@mc-server: /home/minecraft/

After the script finishes, visit the Storage browser in the Cloud Console and click on your bucket. You should see a timestamped backup of your world directory.

Schedule a cron job

Unless you prefer to manually initialize each backup, you'll probably want to have your script run automatically at predictable intervals. To accomplish this task, you need to schedule a new cron job.

To schedule a cron job, begin by opening the cron table for editing:

root@mc-server: crontab -e

Scroll to the bottom of the file and paste the following line, which specifies that will run every 4 hours:

0 */4 * * * /home/minecraft/

Save and exit.

That's it! Your Compute Engine instance will now automatically back up your world data to a Cloud Storage bucket every 4 hours.

Automatically remove old backups

If you back up your world data every 4 hours, that means you're backing it up 6 times a day, 72 times a week, and roughly 300 times a month. You can remove old backups automatically by using a feature of Cloud Storage called Object Lifecycle Management. This feature allows you to configure your Cloud Storage bucket to automatically archive or delete old backups after a certain time or if there are newer backups available.

To set up your Cloud Storage bucket to remove backups automatically:

  1. Open the Cloud Storage browser in the Cloud Console:

    Go to the Cloud Storage browser

  2. In the bucket list, find your Minecraft backups bucket.

  3. Click None in the bucket's Lifecycle column. The View object lifecycle rules page appears.

  4. Click Add rule.

  5. In the Select object conditions section, select Age. Set the age to 7 days and click Continue.

  6. In the Select action section, select Delete and click Continue.

  7. Click Save to save your settings. You're taken back to the View object lifecycle rules page.

Each backup will now be deleted one week after your backup script sends it to Cloud Storage.

Shut down your Minecraft server

If you don't need to run your Minecraft server, you should shut it down to avoid incurring unnecessary expenses.

Begin by establishing an SSH connection with your instance from the VM instances page in your Cloud Console. After the terminal opens, stop the Minecraft server by passing a /stop command to the screen terminal in which it is running.

user@mc-server: sudo screen -r -X stuff '/stop\n'

Now that you've stopped your Minecraft server, you can safely shut down your instance. On the VM instances page, click on your instance's name and then click the Stop button at the top of the page. You will be logged out of your SSH session.

To start up your instance again, visit your instance page and then click the Start button at the top of the page. To start the Minecraft server again, you can establish an SSH connection with the instance, remount your persistent disk, and start your Minecraft server in a new screen terminal, as described in the Run the Minecraft server section.

Automate start up and shutdown procedures

If you plan to shut down your server regularly, consider adding startup and shutdown scripts to your instance to automate common startup and shutdown procedures. You can automate the startup procedure as follows:

  1. Go to the VM instances page in the Cloud Console:

    Go to the VM instances page

  2. Click your instance name.

  3. Click Edit.

  4. In the Custom metadata section, add a new key called startup-script and copy the following script into its Value field:

    mount /dev/disk/by-id/google-minecraft-disk /home/minecraft
    (crontab -l | grep -v -F "/home/minecraft/" ; echo "0 */4 * * * /home/minecraft/")| crontab -
    cd /home/minecraft
    screen -d -m -S mcs java -Xms1G -Xmx3G -d64 -jar server.jar nogui

When you restart your instance, this script will automatically mount your Minecraft disk to the appropriate directory, reinstall your cron job if needed, start your Minecraft server in a screen session, and detach the session.

To automate your shutdown procedure, add another key called shutdown-script and copy the following into its Value field:

sudo screen -r mcs -X stuff '/stop\n'

At the bottom of the page, click Save to commit your changes. When you stop your instance, this script will create a backup of the latest game data and shut down your Minecraft server before the instance shuts down.

What's next

Visit the Minecraft Wiki

The Minecraft Wiki provides tons of useful resources for Minecraft players and Minecraft server administrators alike.

Try an alternative Minecraft server

The vanilla Minecraft server you installed in this tutorial is just one of the many Minecraft servers available. Visit Custom servers in the Minecraft Wiki to see a list of alternative servers that have been optimized for game types, machine requirements, easy modifications, and more.

Try other tutorials

Try out other Google Cloud features for yourself. Have a look at our tutorials.