← Back to Blog
RustTutorial

Deploying Rust Applications on Bare Metal

Rust produces single binaries with no runtime, no garbage collector, and memory safety at compile time. That makes it perfect for bare metal deployment — your binary runs directly on the hardware with minimal overhead. Here is how to build, deploy, and serve a Rust web application on a dedicated server.

Why Rust on Bare Metal

Rust web frameworks like Actix-web and Axum routinely handle 100k+ requests per second on modest hardware. On bare metal, there is no hypervisor stealing cycles and no container overhead. You get the full performance of your dedicated CPU cores, NVMe storage, and memory bandwidth.

Compared to containerized or serverless deployments, a Rust binary on bare metal has the simplest possible deployment: copy one file, start a systemd service, done.

Choosing a Framework

  • Axum — built by the Tokio team. Tower middleware ecosystem, excellent async support, most popular choice for new projects in 2026.
  • Actix-web — fastest in benchmarks, actor-based architecture, mature ecosystem with extensive middleware.
  • Rocket — developer-friendly with macro-based routing, built-in form handling and templating. Great for full-stack apps.

All three produce a single static binary. The deployment process is identical regardless of framework choice.

Step 1: Build a Release Binary

Compile your Rust project in release mode on your development machine or in CI:

# Build optimized release binary
cargo build --release

# Binary location
ls -lh target/release/my-app
# -rwxr-xr-x 1 user user 8.2M my-app

# Optional: strip debug symbols for smaller binary
strip target/release/my-app
# 8.2M -> 3.1M

For cross-compilation to Linux from macOS, use cross or set up the target:

# Install cross-compilation target
rustup target add x86_64-unknown-linux-gnu

# Or use cross (easier)
cargo install cross
cross build --release --target x86_64-unknown-linux-gnu

Step 2: Deploy to Your Server

# Deploy a RAW server
npx rawhq deploy

# Copy binary to server
scp target/release/my-app root@your-server-ip:/usr/local/bin/

# SSH in
ssh root@your-server-ip

# Make executable and test
chmod +x /usr/local/bin/my-app
/usr/local/bin/my-app --version

Step 3: Create a Systemd Service

Systemd keeps your Rust app running, restarts it on crashes, and starts it on boot:

# Create service file
cat > /etc/systemd/system/my-app.service <<EOF
[Unit]
Description=My Rust App
After=network.target

[Service]
Type=simple
User=www-data
ExecStart=/usr/local/bin/my-app
Restart=always
RestartSec=3
Environment=RUST_LOG=info
Environment=PORT=3000

[Install]
WantedBy=multi-user.target
EOF

# Enable and start
systemctl daemon-reload
systemctl enable my-app
systemctl start my-app

# Check status
systemctl status my-app

Step 4: Nginx Reverse Proxy and SSL

# Install Nginx and Certbot
apt update && apt install -y nginx certbot python3-certbot-nginx

# Create Nginx config
cat > /etc/nginx/sites-available/my-app <<EOF
server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1: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;
    }
}
EOF

# Enable site
ln -s /etc/nginx/sites-available/my-app /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx

# Get SSL certificate
certbot --nginx -d yourdomain.com

Performance: Rust vs Node.js

Benchmarks on a 2-core RAW bare metal server (Intel Xeon, 4 GB RAM) using wrk with 100 concurrent connections returning a JSON response:

FrameworkRequests/secAvg Latency
Axum (Rust)142,0000.7 ms
Actix-web (Rust)156,0000.6 ms
Fastify (Node.js)28,0003.5 ms
Express (Node.js)12,0008.2 ms

Rust frameworks deliver 5–12x the throughput of Node.js at a fraction of the latency. On bare metal, this advantage compounds because there is no hypervisor or container runtime consuming resources.

Memory Usage Comparison

Idle memory footprint serving the same JSON API:

RuntimeIdle MemoryUnder Load
Axum (Rust)2 MB8 MB
Node.js (Fastify)45 MB120 MB
Node.js (Express)55 MB180 MB

Rust uses 15–20x less memory. On a 4 GB server, that leaves significantly more headroom for your database, cache, and other services.

CI/CD: Automated Deploys

Add a deploy step to your GitHub Actions workflow:

# .github/workflows/deploy.yml (deploy step)
- name: Build release
  run: cargo build --release
- name: Deploy to server
  run: |
    scp target/release/my-app deploy@server:/usr/local/bin/
    ssh deploy@server "sudo systemctl restart my-app"

No Docker images to build. No container registries. Just copy the binary and restart the service.

Deploy Rust on RAW

npx rawhq deploy

7-day free trial. Dedicated bare metal in 13 seconds. The fastest way to run Rust in production — no containers, no overhead, just your binary on real hardware.