Install llama.cpp on Ubuntu 26.04 or 24.04 with the official Linux installer, then run llama cli with a small GGUF model to start chatting on your own machine.
llama.cpp runs language models on your computer using its CPU or a supported GPU. You can use the same model in the terminal, in your browser, and from an app through a local API.
Before you begin
- 1Check your architecture. Run
uname -m. The Linux installer supportsx86_64andaarch64. - 2Check available memory and disk space. Run
free -handdf -h "$HOME". The Q8_0 text model is about 834 MB on disk. Leave extra memory for Ubuntu and the conversation context. - 3Start with CPU and text. You can follow the terminal and browser examples without a dedicated GPU. Keep an internet connection available for the installer and first model download.
On this page
ToggleInstall llama.cpp on Ubuntu
Step 1. Install the prerequisites
On a fresh Ubuntu 26.04 or 24.04 system, install curl, the system certificate bundle and the OpenMP runtime.
sudo apt update && sudo apt install -y curl ca-certificates libgomp1
Ubuntu 24.04 has no llama.cpp package in its official APT repositories. Ubuntu 26.04 has a llama.cpp metapackage in Universe. The upstream installer and current source releases pick up new GGUF architectures sooner than the fixed Ubuntu package snapshot.
Step 2. Run the official installer and check the version
Run the installer as your regular user. This command fetches and executes the official install script. It puts the command in $HOME/.local/bin/llama.
curl -LsSf https://llama.app/install.sh | sh
case ":$PATH:" in
*":$HOME/.local/bin:"*) ;;
*) export PATH="$HOME/.local/bin:$PATH" ;;
esac
command -v llama
llama version
Expect the full path to the executable and a build version. If a new terminal still cannot find llama, sign out and back in on a default Ubuntu installation, or add export PATH="$HOME/.local/bin:$PATH" to your shell profile.
If the installer reports “No prebuilt llama binary is available for your system,” use the CMake steps below. This can happen on a VM if its reported CPU features do not match a prebuilt variant.
The installed llama command wraps the tools. Run llama cli for terminal chat and llama serve for the server. The standalone CMake tools are named llama-cli, llama-server and llama-bench.
Run a GGUF model in the terminal
Step 3. Start a CPU chat with Qwen
GGUF is a file format that stores a model’s weights and metadata. The Qwen3.5 0.8B GGUF repository provides several variants. Choose Q8_0 for a predictable download and add --no-mmproj to skip the optional vision weights for this text-only test.
llama cli -hf ggml-org/Qwen3.5-0.8B-GGUF:Q8_0 --no-mmproj -ngl 0 -c 2048 --reasoning off
The -ngl 0 flag keeps the model on the CPU, and -c 2048 limits context memory. After the model loads, ask What is an Ubuntu LTS release? Answer in one sentence. You should see a reply and a new prompt. Press Ctrl+C to exit.
The upstream shorthand is llama cli -hf ggml-org/Qwen3.5-0.8B-GGUF. In the tested build, this command also selected Q8_0 for this repository. The explicit tag keeps the example predictable if the publisher adds more variants. The text weights are 833,592,096 bytes for Q8_0, 563,036,064 bytes for Q4_0, and 1,557,662,496 bytes for BF16. Use Q4_0 when memory or disk space is tight. BF16 needs nearly twice as much disk space as Q8_0.
For larger models or different model families, see the guides to Qwen, Meta Llama, and Gemma 4.
Step 4. Reopen the downloaded model offline
Recent builds normally keep downloaded models under $HOME/.cache/huggingface/hub. Custom cache settings can change the location. Use the model path from startup or find the matching snapshot file in the default cache.
The command below prints and reopens the matching snapshot file. With a custom cache location, set MODEL to the full path printed at startup. The -m option loads a local file and works offline once the weights are on disk. The source build examples reuse MODEL, so set it again if you switch terminals.
MODEL=$(find "$HOME/.cache/huggingface/hub" -path '*/snapshots/*' \
-name 'Qwen3.5-0.8B-Q8_0.gguf' -print -quit)
if [ -f "$MODEL" ]; then
printf '%s\n' "$MODEL"
llama cli -m "$MODEL" -ngl 0 -c 2048 --reasoning off
else
printf '%s\n' 'Model missing from the default cache. Check the path printed by llama.cpp.' >&2
fi
Open browser chat and test the local API
Step 5. Start the server
Since build b11521, llama.cpp listens on 127.0.0.1:9931 by default. Start the server in one terminal and leave it running. The alias gives API clients a stable model name.
llama serve -hf ggml-org/Qwen3.5-0.8B-GGUF:Q8_0 --no-mmproj -ngl 0 -c 2048 --reasoning off --alias qwen-local
Open http://127.0.0.1:9931 in a browser on the same Ubuntu machine. Once the model is ready, send a prompt in the built-in chat.
Step 6. Send a request with curl
Open a second terminal. /health reports whether the model is ready. /v1/chat/completions returns an OpenAI-compatible chat response.
curl -fsS http://127.0.0.1:9931/health
curl -fsS http://127.0.0.1:9931/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"qwen-local","messages":[{"role":"user","content":"Say hello in one sentence."}],"max_tokens":32}'
Look for choices[0].message.content in the JSON. The server also exposes the Anthropic-compatible /v1/messages endpoint. Use http://127.0.0.1:9931/v1 as the OpenAI-compatible base URL for apps running directly on the Ubuntu host. See Open WebUI for a separate chat interface or OpenClaw for an assistant that can connect to a local model.
For an older client that expects port 8080, add --port 8080 to the server command or start it with LLAMA_ARG_PORT=8080, then change your client URL to match. Keep the loopback address for local use. Before binding --host 0.0.0.0 on a LAN, set --api-key and restrict access with a firewall. Use TLS if traffic crosses an untrusted network.
Build llama.cpp from source with CMake
Step 7. Build the standalone tools
Build from source when you need a specific release or GPU backend. Current llama.cpp uses OpenSSL for HTTPS model downloads. The old -DLLAMA_CURL=ON flag is obsolete. Run the clone from a directory that does not already contain a llama.cpp checkout.
sudo apt install -y build-essential cmake git pkg-config libssl-dev
git clone https://github.com/ggml-org/llama.cpp.git
cd llama.cpp
git checkout v1.0.0
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DLLAMA_OPENSSL=ON
cmake --build build --parallel 2 --target llama-cli llama-server llama-bench
./build/bin/llama-cli --version
The tag pins the example to a specific release. From the source directory, use ./build/bin/llama-cli -m "$MODEL" -c 2048 to reuse your model. To build the wrapper too, run cmake --build build --parallel 2 --target llama-app and then run ./build/bin/llama. Use the installer route above for the bundled browser UI.
Step 8. Build with Vulkan, CUDA or ROCm
Vulkan is a cross-vendor option on Ubuntu 26.04 and 24.04. Install the development loader, shader compiler and SPIR-V headers. Mesa provides Vulkan drivers for supported Intel and AMD GPUs. NVIDIA users need a working NVIDIA Vulkan driver.
sudo apt install -y libvulkan-dev glslc spirv-headers mesa-vulkan-drivers
cmake -S . -B build-vulkan -DCMAKE_BUILD_TYPE=Release -DGGML_VULKAN=ON
cmake --build build-vulkan --parallel 2 --target llama-cli
./build-vulkan/bin/llama-cli --list-devices
./build-vulkan/bin/llama-cli -m "$MODEL" -c 2048 -ngl 99
For NVIDIA use -DGGML_CUDA=ON, and for supported AMD GPUs use -DGGML_HIP=ON. Give each backend its own CMake build directory. Follow the CUDA and ROCm guide to install and verify the toolchain. Ubuntu 26.04 ships CMake 4.2 and newer glibc headers. Start with CUDA 13.4 or newer on Ubuntu 26.04 and check NVIDIA’s validated distribution list. Skip the older CUDA 13.0 toolkit on 26.04.
Use ./build/bin/llama-cli --list-devices for the CPU build, or run --list-devices on the executable in your GPU build directory. With -ngl 99, look for the GPU name and layer offload count in the startup log. If VRAM runs short, reduce the offload layer count or use a smaller context or model variant.
Fix common llama.cpp problems
The model is slow or runs out of memory
Try -c 2048 or -c 1024 to reduce the memory used for context. This shortens the amount of text the model can use in one conversation. Choose Q4_0 when you need smaller weights, or lower -ngl on a GPU build to keep more layers on the CPU.
The model fails to load
Check that the path points to an existing .gguf file. If the error names an unknown model architecture, update llama.cpp and retry the Qwen example to check that the runtime can load a known model.
Port 9931 is already in use
ss -tlnp | grep ':9931'
If it’s your previous llama.cpp server, stop it with Ctrl+C in its terminal. To keep both processes running, start the new one with a free port, such as --port 9932, then update the client URL.
Update or remove llama.cpp
Step 9. Update the build you use
For the installer, rerun curl -LsSf https://llama.app/install.sh | sh as your regular user and check llama version. For a source build, select the newer upstream tag and build into a separate directory so you can switch back if needed.
Step 10. Remove the program and decide which models to keep
Stop the server first. The installer puts the executable at $HOME/.local/bin/llama and stages its runtime under $HOME/.llama-app. If these paths belong to the installation you want to remove, remove the executable and inspect the runtime directory before deleting it.
rm -i -- "$HOME/.local/bin/llama"
ls -la -- "$HOME/.llama-app"
When you’re ready to remove the staged runtime too, review each deletion when prompted.
rm -ri -- "$HOME/.llama-app"
For a source build, remove its build directory or checkout after saving any local changes. You can keep your GGUFs for another compatible app. To reclaim disk space, inspect and remove the model’s own models--ggml-org--Qwen3.5-0.8B-GGUF directory in the cache. Removing that directory deletes every cached variant for the repository. Other apps may share the Hugging Face cache.
Frequently asked questions
Can llama.cpp run without a GPU?
Yes. Run the model with -ngl 0 to keep its layers on the CPU. Start with a small quantized model and a short context.
Can I use a GGUF file I already downloaded?
Yes. Use -m followed by the full path to the GGUF file. Once the file is on disk, that command can load it offline.
Which port does llama.cpp use?
Current builds default to 127.0.0.1:9931. To use another port, pass --port and update the URL in your browser or API client.
Helpful Resources
Discuss model choices and local hardware.
Find releases and the official tool reference.
Related Ubuntu guides
For other ways to run models locally, visit AI on Ubuntu and the open-source AI tools roundup.
- Install Ollama on Ubuntu for a managed model library.
- Explore Ubuntu developer tools for the rest of your local setup.
