17 April, 2025
Upgrading TeamCity’s Java
Recent versions of TeamCity started to warn about Java 17 support being deprecated. Well, got to update it, right? The trouble is I forgot how to properly override the environment it runs on. It’s super easy when you know where to look…
But first, let’s start with upgrading Java to version 21. Using Ubuntu Server here.
sudo apt install wget gnupg -y
wget -qO - https://repos.azul.com/azul-repo.key | sudo gpg --dearmor -o /usr/share/keyrings/azul.gpg
echo "deb [signed-by=/usr/share/keyrings/azul.gpg] https://repos.azul.com/zulu/deb stable main" | sudo tee /etc/apt/sources.list.d/zulu.list
sudo apt update
sudo apt install zulu21-jdk -y
This should get you a fresh install of Java 21. Now, let’s make it the default – make sure to pick Java 21 from the list when prompted.
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/zulu21/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/zulu21/bin/javac 1
sudo update-alternatives --config java
sudo update-alternatives --config javac
And that’s it! Verify it’s available by running:
java -version
Next, let’s edit TeamCity’s environment. This is the crucial part.
sudo systemctl edit teamcity-server.service
### Editing /etc/systemd/system/teamcity-server.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file
[Service]
Environment="TEAMCITY_SERVER_MEM_OPTS=-Xmx4096m"
Environment="JAVA_HOME=/usr/lib/jvm/zulu21-ca-amd64"
### Lines below this comment will be discarded
The crucial line is bold, note I used the same method to override memory allocation for Java so it’s better suited for our needs. That’s the only way I found to be actually working for TeamCity. Setting global environment variables, editing internal properties won’t work.
After editing the file make sure to reload and restart:
sudo systemctl daemon-reexec
sudo systemctl edit teamcity-server.service
That’s it! After restarting TeamCity will pick up new Java version.