Setting Up a Paper Minecraft Server on Amazon Lightsail

Amazon Lightsail
$20/month (I’m currently testing the $10 version)
4 GB RAM, 2 vCPUs, 80 GB SSD
Ubuntu
Oregon, Zone A (us-west-2a)

https://lightsail.aws.amazon.com/ls/webapp/us-west-2/instances

Network

Add TCP: 25565
Add UDP: 19132

Add a Static IP


Connect
Connect using ssh

Install Java version to match Paper

In terminal

sudo apt-get update && sudo apt-get upgrade

sudo apt-get install ca-certificates apt-transport-https gnupg wget

wget -O – https://apt.corretto.aws/corretto.key | sudo gpg –dearmor -o /usr/share/keyrings/corretto-keyring.gpg && \
echo “deb [signed-by=/usr/share/keyrings/corretto-keyring.gpg] https://apt.corretto.aws stable main” | sudo tee /etc/apt/sources.list.d/corretto.list

To explain that command, it is used to add the Amazon Corretto GPG key and repository to your system, allowing you to install Amazon Corretto using your package manager. Here’s what the command does, step by step:

  1. wget -O - https://apt.corretto.aws/corretto.key: This downloads the Amazon Corretto GPG key and prints it to standard output (-O -).
  2. sudo gpg --dearmor -o /usr/share/keyrings/corretto-keyring.gpg: This converts the GPG key to a format that can be used by APT and saves it to /usr/share/keyrings/corretto-keyring.gpg.
  3. echo "deb [signed-by=/usr/share/keyrings/corretto-keyring.gpg] https://apt.corretto.aws stable main": This command creates a new repository entry for Amazon Corretto in your APT sources list.
  4. sudo tee /etc/apt/sources.list.d/corretto.list: This writes the repository entry to /etc/apt/sources.list.d/corretto.list.

After running this command, you can update your package list and install Amazon Corretto using:

sudo apt update
sudo apt install -y java-17-amazon-corretto-jdk

Replace <version> with the version number you want to install, like 11 or 17.

sudo apt-get update

sudo apt install openjdk-21-jdk

java -version

Should tell you java version 21

Get Paper

https://papermc.io/
download required version
ftp upload to ~/paper
or
wget hooray “url”

Create start file

be sure to match Paper version number
~/paper/start.sh

#!/bin/sh
BINDIR=$(dirname "$(readlink -fn "$0")")
cd "$BINDIR"
java -Xmx2G -jar paper-1.18.1-107.jar

Change the file permissions

chmod 777 ~/paper/start.sh

Run once

~/paper/start.sh

Accept EULA

Delete and copy in world files
Bukket Plugins into plugin folder

Run the server in tmux

This is so the server will continue to run if the terminal is closed

tmux new-session -d -s "paper" ~/paper/start.sh

Connect to the server’s terminal

tmux attach

Create a stop file

To shut the server down cleanly with warning for players
~/paper/goodnight.sh

#
tmux send-keys -t paper "say 1.5 minute until power off" enter
sleep 30
tmux send-keys -t paper "say 1 minute until goodnight" enter
sleep 30
tmux send-keys -t paper "say 30 seconds to power off" enter
sleep 30
tmux send-keys -t paper stop enter
sleep 30

Set the server to stop at night to save CPU

crontab -e
0 23 * * * tmux new-session -d -s "paper" ~/paper/start.sh
0 7 * * * ~/paper/goodnight.sh
0 16 * * 6-7 tmux new-session -d -s "paper" ~/paper/start.sh

Time in UTC
on at 3:00pm
off at 11:00pm
on 8am Sat Sun
https://crontab.guru/