Your Kotlin code works locally. What's next?
\n\nYou've written a cool application in Kotlin. It works perfectly on your laptop, tests pass, endpoints respond instantly. But the real magic begins only when the application goes live — onto a real server where users can see it.
\n\nDeploying Kotlin applications is not just "throwing a jar file onto a server." It's a whole science that includes choosing infrastructure, setting up the environment, ensuring security and fault tolerance. In this article, we'll break down three of the most popular approaches: classic VPS, modern Docker, and flexible cloud platforms. You'll learn how to deploy Kotlin applications using each of these options, get ready-made code examples, and understand which path is best for your project.
\n\nPreparation: What you need to know before deploying Kotlin
\n\nBefore we dive into the details, let's make sure we have the basics. To deploy a Kotlin application, you will need:
\n\n- \n
- A built artifact — usually a JAR file (for Spring Boot, Ktor) or a WAR file (for older Java EE projects). Kotlin compiles to JVM bytecode, so all standard Java tools work perfectly. \n
- Java Runtime Environment (JRE) — at least version 11, but preferably 17 or 21. Kotlin actively uses features from newer Java versions. \n
- A build system — Gradle or Maven. We'll use Gradle, as it is the de facto standard for Kotlin projects. \n
Example of a simple command to build a Kotlin application:
\n\n./gradlew clean build\n\nAfter execution, a JAR file ready to run will appear in the build/libs/ folder.
Deploying Kotlin on VPS: The classic that works
\n\nA Virtual Private Server (VPS) is like having your own apartment. You get full control over the environment, but you also take on all the responsibility for cleaning and security. This approach is ideal for small projects, startups, or when you need maximum flexibility.
\n\nChoosing a VPS and setting up the server
\n\nFor Kotlin applications, any VPS with Linux (Ubuntu 22.04 LTS is an excellent choice) will work. Minimum requirements: 1-2 GB RAM, 20-30 GB SSD. We recommend providers with good support: DigitalOcean, Vultr, Hetzner, or Timeweb (for Russian users).
\n\nAfter purchasing the server, the first thing to do is update packages and install Java:
\n\nsudo apt update && sudo apt upgrade -y\nsudo apt install openjdk-17-jre-headless -y\njava -version\n\nNow let's create a simple user to run the application (never run as root!):
\n\nsudo useradd -m -s /bin/bash kotlinapp\nsudo passwd kotlinapp\n\nRunning a Kotlin application on VPS
\n\nCopy the JAR file to the server via SCP or SFTP:
\n\nscp build/libs/myapp-1.0.0.jar kotlinapp@your-server:/home/kotlinapp/app.jar\n\nNow let's run the application. For simplicity, we'll use nohup so the process doesn't die when SSH is closed:
\n\nnohup java -jar /home/kotlinapp/app.jar --server.port=8080 &\n\nBut this is only the first step. In real life, you will need:
\n- \n
- A systemd service — for automatic restart of the application after crashes and upon server startup. \n
- Nginx — as a reverse proxy for HTTPS, load balancing, and static files. \n
- Monitoring — at least simple logging and uptime checks. \n
Example of a systemd service for a Kotlin application (/etc/systemd/system/kotlinapp.service):
[Unit]\nDescription=Kotlin Application\nAfter=network.target\n\n[Service]\nUser=kotlinapp\nWorkingDirectory=/home/kotlinapp\nExecStart=/usr/bin/java -jar /home/kotlinapp/app.jar --server.port=8080\nRestart=always\nRestartSec=10\n\n[Install]\nWantedBy=multi-user.targe