[Yandex Cloud documentation](../../index.md) > [Tutorials](../index.md) > Application solutions > Other > Deploying a Minecraft server in Yandex Cloud

# Deploying a Minecraft server in Yandex Cloud

Follow this tutorial to deploy the current version of a [Minecraft](https://www.minecraft.net/) ([Java Edition](https://www.minecraft.net/en-us/store/minecraft-java-edition/)) server in Yandex Cloud on an Ubuntu 24.04 [VM](../../compute/concepts/vm.md).

To deploy a Minecraft server in Yandex Cloud:

1. [Get your cloud ready](#prepare-cloud).
1. [Create a security group](#create-sg).
1. [Create a VM for the Minecraft server](#vm-minecraft).
1. [Install the required tools](#install-tools).
1. [Download and run the Minecraft server](#get-and-launch-server).
1. [Test the server](#test-functionality).

If you no longer need the resources you created, [delete them](#clear-out).


## Get your cloud ready {#prepare-cloud}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).

### Required paid resources {#paid-resources}

The infrastructure support cost includes:
* Fee for a continuously running [VM](../../compute/concepts/vm.md) (see [Yandex Compute Cloud pricing](../../compute/pricing.md)).
* Fee for using public IP address and outgoing traffic (see [Yandex Virtual Private Cloud pricing](../../vpc/pricing.md)).

## Create a security group {#create-sg}

Create a [security group](../../vpc/concepts/security-groups.md) with a rule allowing incoming traffic to port `25565`. This is the defalut port for client access in the Minecraft server configuration file. Also, rules allowing SSH access to the VM to configure the server and VM access to the internet to download software will be added to the security group.

{% list tabs group=instructions %}

- Management console {#console}

   1. In the [management console](https://console.yandex.cloud), select your folder.
   1. Navigate to **Virtual Private Cloud**.
   1. In the left-hand panel, select ![image](../../_assets/vpc/security-group.svg) **Security groups**. 
   1. Click **Create security group**.
   1. In the **Name** field, specify the name: `minecraft-sg`.
   1. In the **Network** field, select `default`.
   1. Under **Rules**, [create](../../vpc/operations/security-group-add-rule.md) the following traffic management rules:

      #|
      || **Traffic**
      **direction**
      | **Description** 
      | **Port range**
      | **Protocol**
      | **Source** /
      **Destination name**
      | **CIDR blocks** ||
      || Inbound
      | `Client access to`
      `Minecraft server`
      | `25565`
      | `Any`
      | `CIDR`
      | `0.0.0.0/0` ||
      || Inbound
      | `Access to VM over`
      `SSH`
      | `22`
      | `Any`
      | `CIDR`
      | `0.0.0.0/0` ||
      || Outbound
      | `VM access to`
      `the internet`
      | `0-65535`
      | `Any`
      | `CIDR`
      | `0.0.0.0/0` ||
      |#

   1. Click **Save**.

{% endlist %}


## Create a VM for the Minecraft server {#vm-minecraft}

1. [Create](../../compute/operations/vm-connect/ssh.md#creating-ssh-keys) an SSH key pair:
   ```bash
   ssh-keygen -t ed25519
   ```
   We recommend sticking with the default key file name.

1. Create a VM with a public IP address:

   {% list tabs group=instructions %}

   - Management console {#console}

      1. In the [management console](https://console.yandex.cloud), select the [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) where you want to create your VM.
      1. Navigate to **Compute Cloud**.
      1. In the left-hand panel, select ![image](../../_assets/console-icons/server.svg) **Virtual machines**.
      1. Click **Create virtual machine**.
      1. Under **Boot disk image**, select [Ubuntu 24.04 LTS](https://yandex.cloud/en/marketplace/products/yc/ubuntu-24-04-lts).
      1. Under **Location**, select an [availability zone](../../overview/concepts/geo-scope.md) where your VM will reside.
      1. Under **Disks and file storages**, configure the boot [disk](../../compute/concepts/disk.md):

          * **Type**: `HDD`.
          * **Size**: `18 GB`.

      1. Under **Computing resources**, navigate to the **Custom** tab and specify the Minecraft server recommended parameters:

          * **Platform**: `Intel Ice Lake`
          * **vCPU**: `2`
          * **Guaranteed vCPU performance**: `100%`
          * **RAM**: `2 GB`

      1. Under **Network settings**:

          * In the **Subnet** field, enter the ID of a subnet in the new VM’s availability zone. Alternatively, select a [cloud network](../../vpc/concepts/network.md#network) from the list.

              * Each network must have at least one [subnet](../../vpc/concepts/network.md#subnet). If there is no subnet, create one by selecting **Create subnet**.
              * If there are no networks in the list, click **Create network** to create one:

                  * In the window that opens, specify the network name and select the folder where it will be created.
                  * Optionally, enable the **Create subnets** setting to automatically create subnets in all availability zones.
                  * Click **Create network**.

          * In the **Public IP address** field, select `Auto` to assign the VM a random external IP address from the Yandex Cloud pool. Alternatively, select a static address from the list if you reserved one.
          * In the **Security groups** field, select the `minecraft-sg` security group you created earlier.

      1. Under **Access**, select **SSH key** and specify the VM access credentials:

          * In the **Login** field, enter a name for the user you want to create on the VM, e.g., `ubuntu`.

            {% note alert %}

            Do not use `root` or other OS-reserved usernames. For operations requiring root privileges, use the `sudo` command.

            {% endnote %}

          * In the **SSH key** field, select the SSH key saved in your [organization user](../../organization/concepts/membership.md) profile.
            
            If there are no SSH keys in your profile or you want to add a new key:
            
            1. Click **Add key**.
            1. Enter a name for the SSH key.
            1. Select one of the following:
            
                * `Enter manually`: Paste the contents of the public SSH key. You need to [create](../../compute/operations/vm-connect/ssh.md#creating-ssh-keys) an SSH key pair on your own.
                * `Load from file`: Upload the public part of the SSH key. You need to create an SSH key pair on your own.
                * `Generate key`: Automatically create an SSH key pair.
                
                  When adding a new SSH key, an archive containing the key pair will be created and downloaded. In Linux or macOS-based operating systems, unpack the archive to the `/home/<user_name>/.ssh` directory. In Windows, unpack the archive to the `C:\Users\<user_name>/.ssh` directory. You do not need additionally enter the public key in the management console.
            
            1. Click **Add**.
            
            The system will add the SSH key to your organization user profile. If the organization has [disabled](../../organization/operations/os-login-access.md) the ability for users to add SSH keys to their profiles, the added public SSH key will only be saved in the user profile inside the newly created resource.

      1. Under **General information**, specify the VM name: `minecraft-server`.
      1. Click **Create VM**.

   {% endlist %}

   Recommended virtual machine configuration:

   | Configuration     |   Number of players  |   vCPU  |   RAM  |   Disk size        |
   |------------------|-----------------------|---------|--------|----------------------|
   |   Minimum    |   1-4                 |   2     |   1GB  |   150MB HDD or more  |
   |   Recommended  |   5-10                |   2     |   2GB  |   200MB HDD or more  |
   |   Ideal         |   10+                 |   4     |   4GB  |   200MB SSD or more  |

   {% note warning %}

   Note that this configuration table is in line with the default settings defined in `server.properties`. The bigger the game world grows, the higher the requirements, especially for RAM. In addition, larger rendered areas, villages, and other dynamic objects will result in higher virtual server requirements.

   {% endnote %}


## Install the required tools {#install-tools}

1. [Use SSH to connect](../../compute/operations/vm-connect/ssh.md#vm-connect) to the VM you created.
1. Install the required Java packages from the repository and the `screen` utility to run the terminal session in background mode:

   {% note info %}

   The command below installs OpenJDK version `23`. To start the current Minecraft server version, you may need a newer OpenJDK version. Therefore, check the current OpenJDK version on the [project website](https://openjdk.org/) before you install this package.

   {% endnote %}

   ```bash
   sudo add-apt-repository -y ppa:openjdk-r/ppa \
     && sudo apt update -y \
     && sudo apt install -y openjdk-23-jre-headless screen
   ```

## Download and run the Minecraft server {#get-and-launch-server}

1. Create a separate directory and navigate to it:
   ```bash
   mkdir minecraft-server && cd minecraft-server
   ```

1. Follow [this link](https://www.minecraft.net/en-us/download/server/) and copy the URL to download the distribution of the current server version.
1. Download the current distribution to the current directory using `wget`:
   ```bash
   wget -O minecraft_server.jar <download_link>
   ```

   Where `<download_link>` is the distribution download link you got in the previous step. For example: `https://piston-data.mojang.com/v1/objects/4707d00eb834b446575d89a61a11b5d548d8c001/server.jar`

1. Create the `eula.txt` file to automatically accept the [EULA](https://aka.ms/MinecraftEULA) terms:

   ```bash
   cat << EOF > eula.txt
   eula=true
   EOF
   ```

1. Run the background `screen` session:

   ```bash
   screen
   ```

1. In the background session, run the server:

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

   Wait for the game world to be created.

   ```text
   [09:18:58] [Worker-Main-2/INFO]: Preparing spawn area: 81%
   [09:18:59] [Worker-Main-2/INFO]: Preparing spawn area: 82%
   [09:19:00] [Worker-Main-2/INFO]: Preparing spawn area: 83%
   ...
   [09:19:08] [Worker-Main-2/INFO]: Preparing spawn area: 97%
   [09:19:09] [Server thread/INFO]: Time elapsed: 75917 ms
   [09:19:09] [Server thread/INFO]: Done (92.666s)! For help, type "help"
   ```

1. Optionally, you can leave the `screen` session running in the background by pressing **Ctrl + A + D** and return to the main VM terminal.

   If there is only one such background session with the server running and you want to return to it, run the following command:

   ```bash
   screen -r
   ```

   If there are multiple background sessions, get their list by running the following command:

   ```bash
   screen -list
   ```

   Result:

   ```text
   There is a screen on:
      24257.pts-0.mcft-test	(02/28/2024 09:17:15 AM)	(Detached)
   1 Socket in /run/screen/S-username.
   ```

   Then, enter the session using its ID from the list:
   
   ```bash
   screen -r 24257
   ```

1. After running the server, in the directory, you will see new directories and the files required for server operation and configuration, including the logs:

   ```text
       4096 Mar 16 09:50 .
       4096 Mar 16 09:52 ..
          2 Mar 16 09:16 banned-ips.json
          2 Mar 16 09:16 banned-players.json
         10 Mar 16 09:48 eula.txt
       4096 Mar 16 09:50 libraries
       4096 Mar 16 09:16 logs
   49150256 Dec  7 09:04 minecraft_server_1.20.4.jar
          2 Mar 16 09:16 ops.json
       1303 Mar 16 09:16 server.properties
          2 Mar 16 09:16 usercache.json
       4096 Mar 16 09:50 versions
          2 Mar 16 09:50 whitelist.json
       4096 Mar 16 09:13 world
   ```


## Test the server {#test-functionality}

1. Add the server to the server list in the Minecraft client. Give the server a name of your choice. In the **Server address** field, specify the [public IP address](../../vpc/concepts/address.md#public-addresses) of your `minecraft-server` VM.

   ![add-server-address](../../_assets/tutorials/infrastructure/minecraft-add-server-address.png =750x447)

1. From the server list, select the server you added and click `Connect`.

   ![server-list](../../_assets/tutorials/infrastructure/minecraft-server-list.png =750x449)


## How to delete the resources you created {#clear-out}

To stop paying for the resources you created:
1. [Delete](../../compute/operations/vm-control/vm-delete.md) the `minecraft-server` VM.
1. [Delete](../../vpc/operations/security-group-delete.md) the `minecraft-sg` security group.