Linux Native AI Setup Guide
Running your AI tools natively on bare-metal Linux completely removes the virtualization overhead of a Windows VM. This allows your LLMs to communicate directly with your dual RTX 5060 Ti GPUs, resulting in significantly faster token generation and lower latency.
In this guide, we will:
- Compile llama.cpp from source with CUDA support for maximum GPU performance
- Install & configure llama.cpp & LM Studio as the GUI model manager
- Install OpenClaw and route it to your local LLM server
- Install Hermes Agent and connect it to the same instance
- Set up systemd services so everything auto-starts on boot (after login)
Step 1: Compile llama.cpp from Source (CUDA + Dual GPU)
Section titled “Step 1: Compile llama.cpp from Source (CUDA + Dual GPU)”llama.cpp is the core inference engine that powers both LM Studio and local OpenAI-compatible APIs. Compiling it yourself ensures full CUDA optimization for your dual RTX 5060 Ti GPUs.
Prerequisites
Section titled “Prerequisites”# Install build dependenciessudo apt updatesudo apt install -y build-essential cmake git curl wget
# Install NVIDIA CUDA toolkit (if not already installed)sudo apt install -y nvidia-cuda-toolkitVerify NVIDIA driver and CUDA are working:
nvidia-sminvcc --versionClone & Build llama.cpp
Section titled “Clone & Build llama.cpp”# Clone the repositorygit clone https://github.com/ggml-org/llama.cpp.gitcd llama.cpp
# Pull latest release tag (b9878 as of July 2026)git checkout b9878
# Configure with CUDA enabledcmake -B build \ -DGGML_CUDA=ON \ -DCMAKE_BUILD_TYPE=Release \ -DLLAMA_MAX_DEVICES=2
# Build with all available corescmake --build build --config Release -j$(nproc)Note :
Section titled “Note :”If you happen to face the same error like me, you may use the following trick to fix it.
- Open Terminal and input the following command :
sudo nano /usr/local/cuda-13/targets/x86_64-linux/include/crt/math_functions.h- In your text editor, modify the exact lines you found by adding noexcept(true) right before the closing semicolon, change them to look like this:
For rsqrt (around line 629):extern DEVICE_FUNCTION_DECL device_builtin float rsqrtf(float x) noexcept(true);Second Edit :
For rsqrtf (around line 653):extern DEVICE_FUNCTION_DECL device_builtin float rsqrtf(float x) noexcept(true);Note: Make sure device_builtin has the “t” in it, as it might just be a small typo in your terminal message.
- Save the file (Ctrl + O, then Enter), exit (Ctrl + X), and run your build:
rm -rf buildcmake -B build -DGGML_CUDA=ONcmake --build build --config Release -j$(nproc)Install System-Wide (Optional but Recommended)
Section titled “Install System-Wide (Optional but Recommended)”sudo cmake --install buildThis installs llama-cli, llama-server, and libraries to /usr/local/bin/.
Test the Build
Section titled “Test the Build”Download a small test model and run inference:
# Pull a small model for testing./build/bin/llama-cli -m <your-model.gguf> -ngl 999 -p "Hello, how are you?" -n 32Step 2: Configure llama-server with Tested Parameters (Primary Usage)
Section titled “Step 2: Configure llama-server with Tested Parameters (Primary Usage)”Use the parameters you’ve already tested on Windows — adapted for Linux paths. This is your primary way to run models at full speed.
Key Parameter Breakdown
| Category | Parameter | Purpose |
|---|---|---|
| Model | -m “path” | Main model file (Qwen3.6 27B Q6_K) |
| —mmproj “path” | Vision projection for image understanding | |
| —image-min-tokens 1024 | Minimum tokens for image analysis | |
| Memory | —no-mmap | Load entirely into RAM/VRAM — avoids disk I/O |
| -ngl 99 | Offload all layers to GPU(s) | |
| —split-mode tensor | Tensor parallelism across GPUs | |
| —tensor-split 1,1 | Equal split across dual RTX 5060 Ti (32GB pooled) | |
| Performance | —flash-attn on | Flash attention — faster context processing |
| —batch-size 4096 | Parallel token batch size | |
| —ubatch-size 1024 | Unbatched (single-request) size | |
| —threads 8 / —threads-batch 8 | CPU thread count for preprocessing/postprocessing | |
| Context | —ctx-size 65536 | 64K context window |
| —cache-type-k q4_0 / —cache-type-v q4_0 | Quantized KV-cache — saves VRAM vs BF16 | |
| Sampling | —temp 0.6 / —top-p 0.95 / —top-k 20 / —min-p 0.00 | Temperature & top-p/k sampling for output quality |
| —repeat-penalty 1.1 | Reduces repetitive outputs | |
| Speculative | —spec-type draft-mtp | MTP speculative decoding — faster token generation |
| —spec-draft-n-max 3 / —spec-draft-n-min 2 | Speculative draft range (2-3 tokens) | |
| Chat | —jinja | Enable Jinja chat templating |
| —chat-template-kwargs … | Preserve thinking/reasoning tags in output | |
| Server | —host 0.0.0.0 / —port 8080 | Listen on all interfaces, port 8080 |
| Monitoring | —props / —metrics / —perf | Expose performance metrics & monitoring endpoints |
Shorcut for Shell Script
Section titled “Shorcut for Shell Script”To turn your parameters into a clickable shortcut on your Ubuntu desktop, you need to create a shell script .sh that calls the freshly compiled ./build/bin/llama-server binary, and pair it with a .desktop launcher.
Step 1: Create the Executable Shell Script
- Open a terminal and create the new shell script file:
nano ~/Desktop/qwen27b.sh- Paste the following configuration, which points to your local compiled directory and targets your exact flags:
#!/bin/bashNavigate to your freshly compiled llama.cpp repositorycd "/home/tbn/llama.cpp"
./build/bin/llama-server \ -m "/home/tbn/.cache/lm-studio/models/Qwen3.6-27B/your-model.gguf" \ --mmproj "/home/tbn/.cache/lm-studio/models/Qwen3.6-27B/your-mmproj.gguf" \ --image-min-tokens 1024 \ --no-mmap \ --ctx-size 65536 \ --flash-attn on \ --batch-size 4096 \ --ubatch-size 1024 \ --fit off \ --split-mode tensor \ --tensor-split 1,1 \ --parallel 1 \ --host 0.0.0.0 \ --port 8080 \ -ngl 999 \ --threads 8 \ --threads-batch 8 \ --cache-type-k q8_0 \ --cache-type-v q8_0 \ --temp 0.6 \ --top-p 0.95 \ --top-k 20 \ --min-p 0.00 \ --presence-penalty 0.00 \ --repeat-penalty 1.1 \ --jinja \ --chat-template-kwargs '{"preserve_thinking": true}' \ --reasoning-format none \ --reasoning-budget 16000 \ --props \ --metrics \ --perf \ --spec-type draft-mtp \ --spec-draft-n-max 3 \ --spec-draft-n-min 2
echo ""read -p "Server stopped. Press Enter to exit..." temp-
Save the file by hitting Ctrl + O, click Enter, then exit using Ctrl + X.
-
Grant system execution permissions to the script:
chmod +x ~/Desktop/qwen27b.shStep 2: Create the Double-Click Desktop Launcher Ubuntu requires a .desktop map to launch scripts directly into an active terminal window upon a double-click event.
- Generate the shortcut profile file on your desktop:
nano ~/Desktop/Qwen27b.desktop- Paste the launcher schema layout:
# text[Desktop Entry]Version=1.0Type=ApplicationName=Qwen3.6:27bComment=Launch Local Qwen LLM ServerExec=/home/tbn/Desktop/qwen27b.shIcon=utilities-terminalTerminal=trueCategories=Development;- Save and close (Ctrl + O, Enter, Ctrl + X).
Step 3: Authorize Execution on the Desktop
-
Minimize your windows and locate the new QwenServer.desktop file on your actual Ubuntu desktop screen.
-
Right-click on the icon.
-
Click and select “Allow Launching” from the context dropdown menu.
The file icon will automatically transform into a system terminal grid logo. You can now double-click it anytime to host your model’s OpenAI-compatible API on port 8080 instantly.
Verify It Works
Section titled “Verify It Works”In another terminal:
Check model is loadedcurl http://127.0.0.1:8080/v1/models | python3 -m json.toolQuick chat test
Section titled “Quick chat test”curl http://127.0.0.1:8080/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"model":"Qwen3.6-27B","messages":[{"role":"user","content":"Hello"}]}' | python3 -m json.toolCheck GPU memory usage (both GPUs should show VRAM activity)
Section titled “Check GPU memory usage (both GPUs should show VRAM activity)”nvidia-smiStep 3: Install LM Studio as Backup/Alternative
Section titled “Step 3: Install LM Studio as Backup/Alternative”LM Studio is a convenient GUI fallback — use it for quick model downloads and as a backup server if llama.cpp needs maintenance.
Download & Install
Section titled “Download & Install”cd ~/Downloads
# Download latest AppImage from lmstudio.ai/downloadwget https://github.com/AIDot-OpenLLM/lm-studio/releases/latest/download/LM-Studio-x86_64.AppImage -O LM-Studio.AppImage
chmod +x LM-Studio.AppImageFirst Launch & Model Setup
Section titled “First Launch & Model Setup”- Double-click
LM-Studio.AppImageto launch - Go to the 🔍 Search tab → search for
Qwen3.6:27bor your preferred model - Click Download and wait for it to finish (stores in
~/.cache/lm-studio/models/)
Configure Server Settings
Section titled “Configure Server Settings”Navigate to the 🔄 Local Server tab and configure:
| Setting | Value | Notes |
|---|---|---|
| Context Length | 65536 (Max) | 65K context window |
| GPU Offload | MAX | All layers on GPU — essential for speed |
| K/V Cache Quantization | Q4_0 | Balances memory vs quality |
| Host | 127.0.0.1 | Local only (change to 0.0.0.0 for network access) |
| Port | 1234 | Default port |
Start the Server
Section titled “Start the Server”Click “Start Server” — it will listen on:
http://127.0.0.1:1234/v1Test the API endpoint:
curl http://127.0.0.1:1234/v1/models | python3 -m json.toolYou should see your loaded model listed.
Step 4: Install & Configure OpenClaw
Section titled “Step 4: Install & Configure OpenClaw”OpenClaw is an AI agent framework that connects to local LLM backends. Since LM Studio runs locally, routing is straightforward.
Install OpenClaw
Section titled “Install OpenClaw”# Install via npm (recommended)npm install -g openclaw
# Verify installationopenclaw --versionConfigure OpenClaw to Use Local llama.cpp Server
Section titled “Configure OpenClaw to Use Local llama.cpp Server”openclaw configureWhen prompted:
- Model Provider: Select
OpenAI Compatible - API Base URL: Enter
http://127.0.0.1:8080/v1(your llama-server port) - API Key: Leave empty or type
llama-cpp(not required for local hosting) - Model Name: Your loaded model name
Verify Connection
Section titled “Verify Connection”openclaw dashboardOpenClaw should connect to your llama.cpp server and display the active model.
Step 5: Install & Configure Hermes Agent
Section titled “Step 5: Install & Configure Hermes Agent”Hermes Agent is a full-featured AI assistant that can connect to local LLM servers via OpenAI-compatible endpoints.
Install Hermes Agent
Section titled “Install Hermes Agent”# Run the official installercurl -sSL https://hermes-agent.com | bash
# Verify installationhermes --versionConfigure Hermes to Use Local llama.cpp Server
Section titled “Configure Hermes to Use Local llama.cpp Server”hermes setup
During setup:
1. **Provider:** Choose `OpenAI Compatible`2. **Base URL:** Enter`http://127.0.0.1:8080/v1` (same as OpenClaw)3. **API Key:** Type `llama-cpp` (no real key needed for local hosting)4. **Model:** Your loaded model nameTest Hermes Agent
Section titled “Test Hermes Agent”hermes chat "Hello, can you hear me?"Hermes should respond using your locally hosted model.
Step 6: Set Up Auto-Start on Boot (systemd Services)
Section titled “Step 6: Set Up Auto-Start on Boot (systemd Services)”Make all services start automatically when Ubuntu boots — they’ll launch as soon as you log in.
Create a systemd Service for llama-server
Section titled “Create a systemd Service for llama-server”Create the service file:
sudo nano /etc/systemd/system/llama-cpp.serviceAdd this content (adjust paths to match your setup):
[Unit]Description=llama.cpp Server (CUDA)After=network.target nvidia-driver.serviceWants=nvidia-driver.service
[Service]Type=simpleUser=tbnWorkingDirectory=/home/tbnExecStart=/usr/local/bin/llama-server \ -m /home/tbn/.cache/lm-studio/models/Qwen3.6-27B/your-model.gguf \ --host 127.0.0.1 \ --port 8080 \ -ngl 999 \ --tensor-split 50:50 \ -c 65536 \ -tb 4096 \ --mlock \ -ctk q4_0Restart=on-failureRestartSec=5
[Install]WantedBy=default.targetNote: Replace the --model path with your actual model file location. You can find it in LM Studio’s model browser.
Create a systemd Service for OpenClaw
Section titled “Create a systemd Service for OpenClaw”sudo nano /etc/systemd/system/openclaw.service[Unit]Description=OpenClaw AI AgentAfter=llama-cpp.serviceRequires=llama-cpp.service
[Service]Type=simpleUser=tbnWorkingDirectory=/home/tbnExecStart=openclaw serve --host 127.0.0.1 --port 8080Restart=on-failureRestartSec=5
[Install]WantedBy=default.targetCreate a systemd Service for Hermes Agent
Section titled “Create a systemd Service for Hermes Agent”sudo nano /etc/systemd/system/hermes-agent.service[Unit]Description=Hermes AI AgentAfter=openclaw.service llama-cpp.serviceRequires=llama-cpp.service
[Service]Type=simpleUser=tbnWorkingDirectory=/home/tbnExecStart=hermes serve --host 127.0.0.1 --port 9000Restart=on-failureRestartSec=5
[Install]WantedBy=default.targetEnable & Start All Services
Section titled “Enable & Start All Services”# Reload systemd to pick up new servicessudo systemctl daemon-reload
# Enable all services (auto-start on boot)sudo systemctl enable llama-cpp.servicesudo systemctl enable openclaw.servicesudo systemctl enable hermes-agent.service
# Start them now (without rebooting)sudo systemctl start llama-cpp.servicesudo systemctl start openclaw.servicesudo systemctl start hermes-agent.serviceVerify Services Are Running
Section titled “Verify Services Are Running”systemctl status llama-cpp.servicesystemctl status openclaw.servicesystemctl status hermes-agent.serviceAll three should show active (running).
Check Logs (If Something Goes Wrong)
Section titled “Check Logs (If Something Goes Wrong)”journalctl -u lm-studio-server.service -fjournalctl -u openclaw.service -fjournalctl -u hermes-agent.service -fQuick Reference: Service Management Commands
Section titled “Quick Reference: Service Management Commands”| Action | Command |
|---|---|
| Start all | sudo systemctl start llama-cpp openclaw hermes-agent |
| Stop all | sudo systemctl stop llama-cpp openclaw hermes-agent |
| Restart one | sudo systemctl restart ‘service-name’ |
| Check status | systemctl status ‘service-name’ |
| View logs | journalctl -u ‘service-name’ -f |
| Disable auto-start | sudo systemctl disable ‘service-name’ |
Troubleshooting
Section titled “Troubleshooting”llama.cpp doesn’t detect GPU
Section titled “llama.cpp doesn’t detect GPU”# Check NVIDIA driver is loadednvidia-smi
# Check CUDA visibilityenv | grep -i cuda
# Rebuild with verbose output to see compiler flagscmake --build build --config Release -j$(nproc) 2>&1 | grep -i cudaServices fail to start on boot
Section titled “Services fail to start on boot”Make sure: User= field matches your username (replace “tbn” if different) Model path in llama-cpp.service is correct and the file exists Test manually first before relying on systemd:
sudo -u tbn /usr/local/bin/llama-server \ -m /path/to/your/model.gguf \ --host 127.0.0.1 --port 8080 -ngl 999 -c 4096Port conflicts
Section titled “Port conflicts”If ports 1234, 8080, or 9000 are already in use, change them in the service files and configuration wizards.
Summary
Section titled “Summary”You now have a fully native Linux AI stack:
✅ llama.cpp compiled from source with CUDA — maximum GPU performance
✅ **Dual RTX 5060 Ti GPUs** pooled via tensor splitting (32GB VRAM)✅ **llama-server** running as OpenAI-compatible API on port 8080✅ **LM Studio** used only for model downloads (not inference)✅ **OpenClaw** connected to llama.cpp server✅ **Hermes Agent** also using the same llama.cpp instance✅ **All services auto-start on boot** via systemd
Your dual GPUs are now directly powering your AI agents with zero virtualization overhead. Enjoy the speed! 🚀---