Skip to content

Instantly share code, notes, and snippets.

@tolache
Last active May 12, 2026 08:37
Show Gist options
  • Select an option

  • Save tolache/c71d6fed3b13940190e8a7552d54f30f to your computer and use it in GitHub Desktop.

Select an option

Save tolache/c71d6fed3b13940190e8a7552d54f30f to your computer and use it in GitHub Desktop.
How to install TeamCity (Amazon Linux 2 / Ubuntu example)

How to install TeamCity (Amazon Linux 2023 / Ubuntu example)

Constants

They will be used in the installation process. Change them if you need to.

TC_VERSION="2026.1"
LINUX_USERNAME="$USER" # TeamCity service will start on behalf of the current user
LINUX_USERGROUP=$LINUX_USERNAME
TEAMCITY_HOME="/opt/teamcity" # directory where you want to install TeamCity server
AGENT_HOME="$TEAMCITY_HOME/buildAgent" # [optional] agent directory (if you want to run a build agent on the same machine - do NOT do this in production)

Install Java

sudo yum install java-21-amazon-corretto-headless

For Ubuntu, refer to official Amazon docs.

Verify installation.

java --version

Install TeamCity

Download the distribution.

wget https://download.jetbrains.com/teamcity/TeamCity-$TC_VERSION.tar.gz

Create the install dir and set permissions.

sudo mkdir $TEAMCITY_HOME
sudo chown -R $LINUX_USERNAME:$LINUX_USERGROUP $TEAMCITY_HOME

Extract the files and put them into the install dir.

tar -zxf TeamCity-$TC_VERSION.tar.gz
mv TeamCity/* $TEAMCITY_HOME

Clean up temp files.

rm TeamCity-$TC_VERSION.tar.gz
rm -r TeamCity

Configure TeamCity JVM heap memory

Save the variabile globally and force the shell to load it without reboot.

echo "TEAMCITY_SERVER_MEM_OPTS=-Xmx4g" | sudo tee -a /etc/environment >/dev/null
source /etc/environment

Register TeamCity as a service and start service automatically on reboot

Create a systemd service configuration file.

sudo tee /etc/systemd/system/teamcity-server.service > /dev/null <<EOF
[Unit]
Description=TeamCity Server
After=network.target

[Service]
Type=forking
PIDFile=$TEAMCITY_HOME/logs/teamcity.pid
ExecStart=$TEAMCITY_HOME/bin/teamcity-server.sh start
ExecStop=$TEAMCITY_HOME/bin/teamcity-server.sh stop
User=$LINUX_USERNAME
Group=$LINUX_USERGROUP
EnvironmentFile=/etc/environment

[Install]
WantedBy=multi-user.target
EOF

Enable service startup on reboot and start the service.

sudo systemctl enable teamcity-server.service
sudo systemctl start teamcity-server.service

[Optional] Register TeamCity Build Agent a service and start service automatically on reboot

Warning

This is for PoC only! Do NOT run the agent on the same machine as the server in production!

Create a systemd service configuration file.

sudo tee /etc/systemd/system/teamcity-agent.service > /dev/null <<EOF
[Unit]
Description=TeamCity Build Agent
After=network.target

[Service]
Type=oneshot

User=$LINUX_USERNAME
Group=$LINUX_USERGROUP
ExecStart=$AGENT_HOME/bin/agent.sh start
ExecStop=-$AGENT_HOME/bin/agent.sh stop

# Support agent upgrade as the main process starts a child and exits then
RemainAfterExit=yes
# Support agent upgrade as the main process gets SIGTERM during upgrade and that maps to exit code 143
SuccessExitStatus=0 143

[Install]
WantedBy=default.target
EOF

Enable service startup on reboot and start the service.

sudo systemctl enable teamcity-agent.service
sudo systemctl start teamcity-agent.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment