🎁 Try it for free - Get free credits instantly after registration!
  • Home
  • Blog
  • Install NATS on Ubuntu 24 LTS

Install NATS on Ubuntu 24 LTS


A practical, production-ready guide for installing and configuring NATS Server on Ubuntu 24.04 LTS: binary install, service setup, config tuning, JetStream persistence, and monitoring endpoints.

Installing NATS Server on Ubuntu 24.04 LTS (Production Setup)

NATS is a lightweight, high-performance messaging system for distributed services, microservices, and real-time data pipelines. It’s small, fast, and simple to run — perfect for IPAM systems, telemetry, or coordination between app components.

1. Update and Prepare Environment

sudo apt update && sudo apt install -y curl wget unzip jq

2. Download and Install NATS Server

cd /tmp
wget https://github.com/nats-io/nats-server/releases/download/v2.10.18/nats-server-v2.10.18-linux-amd64.zip
unzip nats-server-v2.10.18-linux-amd64.zip
sudo mv nats-server-v2.10.18-linux-amd64/nats-server /usr/local/bin/
sudo chmod +x /usr/local/bin/nats-server
nats-server --version

3. Create Configuration File

sudo mkdir -p /etc/nats
sudo tee /etc/nats/nats-server.conf >/dev/null <<'EOF'
port: 4222
server_name: "nats-main"

jetstream {
  store_dir: "/var/lib/nats/jetstream"
  max_mem_store: 1Gb
  max_file_store: 10Gb
}

http: 8222
EOF

4. Add systemd Unit

sudo tee /etc/systemd/system/nats.service >/dev/null <<'EOF'
[Unit]
Description=NATS Server
After=network.target

[Service]
ExecStart=/usr/local/bin/nats-server -c /etc/nats/nats-server.conf
User=root
Restart=always
LimitNOFILE=100000

[Install]
WantedBy=multi-user.target
EOF

5. Enable and Start

sudo systemctl daemon-reload
sudo systemctl enable --now nats
sudo systemctl status nats

6. Verify Monitoring Endpoint

curl http://127.0.0.1:8222/varz | jq .

7. Install NATS CLI

curl -Ls https://install.nats.io/nats-io/natscli/nats@latest | sudo bash
nats --version

8. Persistence and JetStream

sudo mkdir -p /var/lib/nats/jetstream
sudo chown -R nobody:nogroup /var/lib/nats

9. Open Ports

sudo ufw allow 4222/tcp
sudo ufw allow 8222/tcp

10. Cluster Example

cluster {
  name: "nats-cluster"
  listen: 0.0.0.0:6222
  routes: [
    nats-route://10.0.0.2:6222,
    nats-route://10.0.0.3:6222
  ]
}

Wrap-Up

Now you have a fully configured NATS server ready for production use on Ubuntu 24.04 with systemd integration, JetStream persistence, and monitoring endpoints enabled.