Host your own Minecraft server on Google Cloud for Free

İbrahim BABAL
4 min readAug 30, 2024

--

I love playing Minecraft with my friends. But It sucks that my computer needs to be on for them to play. So I often leave my computer on before sleep so they can continue playing. So today we will solve this problem by creating our server on the cloud on 7/24 and completely free.

1. Create a Google Cloud Account

Go to https://cloud.google.com and create an account. It will ask you for credit card information to prove you are human. Do not worry because you will not charged until you manually activate your paid account as per the following sentence:

Automatic payments only begin once you manually activate a paid Google Cloud account.

When you create your account google will give you 300 dollar credit for 3 months. This is more than enough for our server.

  • Do I get charged if I exceed my Google Cloud credits on a free account?
    - NO! You will not charged in any way unless you manually activate a paid account!
  • Am I gonna get charged when the free trial ends end I forgot the server on.
    -
    Still NO! You will not get charged unless you activate a paid account!

So do not upgrade your account to a paid tier unless you know what you are doing!

2. Create a Virtual Machine

Go to Compute Engine > VM Instances and click Create Instance.

  • Name= -name it whatever you want-
  • Region= -select the one closes to you-
  • Zone= Any
  • Machine configuration=E2
  • Machine Type= e2-medium
  • Firewall= Allow HTTP and HTTPS traffic

After you select all the options above, click the Create button below.

3. Setup Java

Once your server is initiated and ready click the SSH button in the list, after you click there will be a window open with a terminal connected to your server.

First, update your dependencies

sudo apt update
sudo apt upgrade

Then, download SDKMAN!

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

Install Java

sdk install java

4. Install Minecraft Server

First, copy the download link from Minecraft Official Website then download Minecraft using wget.

Create a folder called minecraft-server and cd into it.

mkdir ~/minecraft-server
cd ~/minecraft-server

Then download Minecraft with the link you have like below (paste your own link)

wget https://launcher.mojang.com/v1/objects/[server_version_hash]/server.jar -O server.jar

Then start the server:

java -Xmx1024M -Xms1024M -jar server.jar nogui

Minecraft will generate the necessary files and will ask you to accept eula so change the text yourself or run the following:

echo "eula=true" > eula.txt

Now our Minecraft server is ready to launch but we need to make some configurations to access it with our computers.

5. Configure Firewall

Install ufw to set firewall rules:

sudo apt update
sudo apt install ufw

Enable ufw:

sudo ufw enable

And allow the port used by your Minecraft server (default is 25565):

sudo ufw allow 25565/tcp

don’t forget to allow the ssh port before closing the terminal window. (If you don’t you can not access the ssh terminal. But you can fix it somehow.)

sudo ufw allow 22/tcp

Now our server's firewall is done. Now we need to configure virtual machine firewalls on Google Cloud. Navigate to VPC network > Firewall rules. Click Create Firewall Policy and Set the following:

  • Name: minecraft-server-rule
  • Network: Default
  • Targets: All instances in the network
  • Source IP ranges: 0.0.0.0/0 (This allows access from any IP address)
  • Protocols and ports: tcp:25565

Click Create

6. Launch the Server

We can launch the server now but we would want to start the server in a process so it will not terminate after we close the terminal. So we need to install Screen.

sudo apt install screen

Run screen

screen

Then launch the minecraft server

java -Xmx1024M -Xms1024M -jar server.jar nogui

Now you can exit that window with ctrl + a + d and your server will keep running. You can learn more about screen and attach/detach windows.

You can change the properties of your server by changing server.properties the file located next to the server itself.

7. Connect to your server

Open Minecraft and navigate to Multiplayer > Add Server. Give it a name and put your server ip + the port that the game is running like xx.xx.xx.xx:25565 you can see your servers ip like below:

And that's all. Now your friends can enjoy the world even when you are offline (I’m not sure if it's a good thing or bad). This is just a start, you can learn to protect your server, manage people with server management add-ons, and many more.

Don’t forget to get your world's backup before the free trial ends. Then you can do the same thing and continue running your server free.

--

--