Deploying Ring App on Ubuntu 26.04
Once you have coded a Ring app,
$ lein ring uberjar
This will create a standalone JAR file in the target directory. Let’s renameit to my-app.jar for convenience.
Here’s how to host your Clojure Ring app on an Ubuntu VPS:
1. Install Java
sudo apt update
sudo apt install openjdk-25-jre-headless
java -version # verify
2. Upload the JAR
From your local machine:
scp my-app.jar user@your-vps-ip:/home/user/
3. Run it manually first (sanity check)
java -jar my-app.jar
Your app likely starts on port 3000 by default. You can override it:
PORT=8080 java -jar my-app.jar
You can use browser to test your app at http://your-vps-ip:3000, or http://your-vps-ip:8080 if you set a custom port.
4. Set up a systemd service (so it runs forever)
Create a service file:
sudo nano /etc/systemd/system/my-app.service
Paste this:
[Unit]
Description=My Clojure Ring App
After=network.target
[Service]
User=user
WorkingDirectory=/home/user
ExecStart=/usr/bin/java -jar /home/user/my-app.jar
Restart=always
RestartSec=5
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
Enable and start it:
sudo systemctl daemon-reload
sudo systemctl enable my-app
sudo systemctl start my-app
sudo systemctl status my-app
5. Set up Nginx as a reverse proxy
sudo apt install -y nginx
Create a config:
sudo nano /etc/nginx/sites-available/my-app
server {
listen 80;
server_name your-domain.com; # or your VPS IP
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable it:
sudo ln -s /etc/nginx/sites-available/my-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
6. Open the firewall
sudo ufw allow 'Nginx Full'
sudo ufw allow OpenSSH
sudo ufw enable
7. Add HTTPS with Let’s Encrypt (optional but recommended)
sudo snap install --classic certbot # install certbot
sudo ln -s /snap/bin/certbot /usr/local/bin/certbot # Prepare the Certbot command
sudo certbot --nginx # follow the prompts to set up HTTPS
Certbot will auto-edit your Nginx config and set up auto-renewal.
Useful commands after deployment:
sudo systemctl restart my-app # restart after uploading new jar
sudo journalctl -u my-app -f # tail logs
sudo systemctl status my-app # check status
When you deploy a new version, just scp the new jar over and sudo systemctl restart my-app.