Run LM Studio Headless on Ubuntu with llmster and systemd
Use llmster to run LM Studio on Ubuntu without a desktop session. Prove the model and API work from a normal user shell, then configure systemd to repeat those known-good steps at boot. Keep the API on loopback for a local app or SSH tunnel.
1. Install llmster under the service account
Choose the non-root Linux account that will own the downloaded models and run the service. In the commands below, MODEL_ID is a placeholder for a compatible model you choose. Download the official installer under that user, review it, then run it.
curl -fsSL https://lmstudio.ai/install.sh -o install-llmster.sh
less install-llmster.sh
bash install-llmster.sh
~/.lmstudio/bin/lms --help
2. Load and verify a model manually
~/.lmstudio/bin/lms daemon up
~/.lmstudio/bin/lms get MODEL_ID
~/.lmstudio/bin/lms load MODEL_ID
~/.lmstudio/bin/lms server start --port 1234
curl --fail-with-body http://127.0.0.1:1234/v1/models
ss -ltn | grep ':1234'Check the model ID and the bind address. Send a small inference request before automating the startup. A successful models response only proves the server can answer discovery requests.
curl --fail-with-body http://127.0.0.1:1234/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"ID_FROM_V1_MODELS","messages":[{"role":"user","content":"Reply with ready."}],"max_tokens":16}'Stop the manually launched daemon with ~/.lmstudio/bin/lms daemon down before handing startup to systemd.
3. Enable startup with systemd
Save the unit as /etc/systemd/system/lmstudio.service. Replace LLM_USER with the account name, replace the home path if it differs, and use the model reference you successfully loaded. This is adapted from the official Linux startup guide.
[Unit]
Description=LM Studio local inference
[Service]
Type=oneshot
RemainAfterExit=yes
User=LLM_USER
Environment=HOME=/home/LLM_USER
ExecStartPre=/home/LLM_USER/.lmstudio/bin/lms daemon up
ExecStartPre=/home/LLM_USER/.lmstudio/bin/lms load MODEL_ID --yes
ExecStart=/home/LLM_USER/.lmstudio/bin/lms server start --port 1234
ExecStop=/home/LLM_USER/.lmstudio/bin/lms daemon down
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now lmstudio.service
systemctl status lmstudio.service
journalctl -u lmstudio.service -n 100 --no-pager
curl --fail-with-body http://127.0.0.1:1234/v1/models
4. Verify after boot and troubleshoot
After a planned reboot, verify service status and rerun the inference request. The unit starts the daemon and server. Its active (exited) state alone does not continuously prove the endpoint is healthy. Monitor a local API request if another app depends on serving availability.
- Command works in a shell but fails at boot: verify absolute paths, service username, home directory and model permissions.
- Service stalls while loading: test the same quantization manually and inspect memory. Use a smaller model and context before changing timeouts.
- Port already in use: look up the listener with
sudo ss -ltnp. Check for a manually started server or an existing app before choosing a different port. - Remote app cannot connect: first verify localhost inference. If you need personal remote access, an SSH local forward such as
ssh -N -L 1234:127.0.0.1:1234 user@serverkeeps the model port private.
FAQ
Can I load models on demand?
Yes. The official startup guide describes removing eager model loading and using just-in-time loading. Expect cold-start latency and test what happens when the first request arrives.
Should I use this unit to restart after a daemon crash?
This oneshot unit is designed for startup and shutdown. Use an endpoint health check to identify a failed daemon before choosing how to restart it. For a coding client, see Codex with LM Studio.
