Compute Comparison
How-To Guides10 min read

How to Run Llama 3 Locally: Complete Setup Guide (2026)

Step-by-step guide to running Llama 3 locally on your own hardware — hardware requirements, Ollama vs llama.cpp vs LM Studio, quantization, and performance benchmarks.

Llama 3 is Meta's open-weight model family — 8B, 70B, and 405B parameter variants released under a permissive licence that allows commercial use. Running it locally means zero per-token API costs, full data privacy, and no rate limits. The trade-off is upfront hardware cost and setup time. This guide covers every step: hardware requirements, software stack, model download, and running your first inference — on both Mac (Apple Silicon) and Linux/Windows with an NVIDIA GPU.

Hardware requirements

The minimum viable setup depends on which Llama 3 variant you want to run. The 8B model in 4-bit quantised form (Q4_K_M) fits in 6 GB of VRAM — an RTX 3060 or RTX 4060 handles it comfortably. The 70B model needs ~40 GB of VRAM at Q4, which means either a single A100 80GB, two RTX 3090s in NVLink, or offloading layers to system RAM (slower). The 405B model requires 200+ GB — practical only on multi-GPU cloud instances.

Apple Silicon Macs use unified memory shared between CPU and GPU, which makes them surprisingly capable. An M2 Pro with 32 GB runs the 70B Q4 model at 8–12 tokens/second — slower than a dedicated GPU but silent, efficient, and no cloud bill. An M3 Max with 128 GB can run the 405B model, albeit slowly.

For Linux/Windows, the recommended minimum is an NVIDIA GPU with 8+ GB VRAM (RTX 3060 or better) and CUDA 12.x drivers. AMD GPUs work via ROCm but require extra configuration. CPU-only inference is possible but expect 1–3 tokens/second on a modern desktop CPU — usable for testing, not production.

Choosing your inference engine

Three tools dominate local Llama inference: **llama.cpp**, **Ollama**, and **LM Studio**. Each targets a different user.

**llama.cpp** is the lowest-level option — a C++ inference engine that runs quantised GGUF models on CPU and GPU. It has the best raw performance and the most configuration options, but requires command-line comfort. It supports CUDA, Metal (Apple Silicon), ROCm, and Vulkan backends.

**Ollama** wraps llama.cpp in a clean CLI and REST API. One command downloads and runs any model from the Ollama library. It exposes an OpenAI-compatible API at `http://localhost:11434`, so any app built for OpenAI works with Ollama by changing the base URL. This is the fastest path to a working local LLM.

**LM Studio** is a GUI application for Mac and Windows. It has a built-in model browser, chat interface, and local server. Best for non-technical users or anyone who wants a visual interface rather than a terminal.

Installing Ollama (recommended path)

Ollama is the fastest way to get Llama 3 running locally. Install it with one command:

**Mac/Linux:** `curl -fsSL https://ollama.com/install.sh | sh`

**Windows:** Download the installer from ollama.com and run it. Ollama installs as a background service and adds the `ollama` CLI to your PATH.

Once installed, pull and run Llama 3.1 8B: `ollama run llama3.1`. Ollama downloads the Q4_K_M quantised model (~4.7 GB), loads it, and opens an interactive chat prompt. For the 70B model: `ollama run llama3.1:70b`. For the 405B: `ollama run llama3.1:405b` (requires 230+ GB RAM/VRAM).

To use Ollama as an API server (for building apps), it's already running at `http://localhost:11434`. The OpenAI-compatible endpoint is at `http://localhost:11434/v1/chat/completions`. Set `OPENAI_BASE_URL=http://localhost:11434/v1` and `OPENAI_API_KEY=ollama` in your app and it works with any OpenAI SDK.

Installing llama.cpp (maximum performance)

For maximum control and performance, build llama.cpp from source. First install prerequisites: `git`, `cmake`, and CUDA Toolkit 12.x (for NVIDIA GPUs).

Clone and build: `git clone https://github.com/ggerganov/llama.cpp && cd llama.cpp && cmake -B build -DGGML_CUDA=ON && cmake --build build --config Release -j$(nproc)`. For Apple Silicon, replace `-DGGML_CUDA=ON` with `-DGGML_METAL=ON`.

Download a GGUF model from Hugging Face. The recommended Llama 3.1 8B quantisation is `Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf` (~4.7 GB). Use the Hugging Face CLI: `pip install huggingface_hub && huggingface-cli download bartowski/Meta-Llama-3.1-8B-Instruct-GGUF --include "*Q4_K_M*" --local-dir ./models`.

Run inference: `./build/bin/llama-cli -m ./models/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf -p "Explain transformer attention in one paragraph" -n 256 --gpu-layers 35`. The `--gpu-layers` flag offloads layers to GPU — set it to 99 to push everything to VRAM, or lower values to split between GPU and CPU RAM.

Start the OpenAI-compatible server: `./build/bin/llama-server -m ./models/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf --port 8080 --gpu-layers 35`. This exposes `http://localhost:8080/v1/chat/completions`.

Performance benchmarks by hardware

Tokens per second (generation speed) varies significantly by hardware. For Llama 3.1 8B Q4_K_M: RTX 4090 (~80–100 t/s), RTX 3090 (~60–75 t/s), RTX 4060 (~35–45 t/s), M3 Max 40-core GPU (~45–55 t/s), M2 Pro 19-core GPU (~25–35 t/s), CPU-only Ryzen 9 7950X (~8–12 t/s).

For Llama 3.1 70B Q4_K_M: A100 80GB (~25–35 t/s), dual RTX 3090 NVLink (~20–28 t/s), M3 Max 128GB (~8–12 t/s), CPU-only with 128 GB RAM (~1–2 t/s).

Prompt processing (prefill) speed is typically 3–5x faster than generation. A 2,000-token system prompt processes in under a second on an RTX 4090. Context window size affects VRAM usage linearly — a 32K context with the 8B model needs ~2 GB more VRAM than an 8K context.

See live GPU cloud prices if you want to compare the cost of renting these GPUs vs buying hardware outright.

Cost comparison: local vs managed API

The break-even point between local hardware and managed APIs depends on your token volume. An RTX 4090 costs ~$1,600 new. At $0.30/1M tokens (Together AI Llama 3.1 70B rate), you break even after generating ~5.3 billion tokens — roughly 18 months of moderate use (10M tokens/day).

For the 8B model, managed API rates are as low as $0.06/1M tokens (Groq). An RTX 4060 at $300 breaks even after 5 billion tokens. At 5M tokens/day that's under 3 years — marginal unless you have high volume or strict data privacy requirements.

The real case for local inference is privacy and latency, not cost. If your data can't leave your network, local is the only option regardless of price. If you need sub-100ms first-token latency, a local GPU on the same machine beats any API. Use the LLM ROI Calculator to model your specific volume.

Frequently asked questions

Can I run Llama 3 on a CPU without a GPU?
Yes. llama.cpp and Ollama both support CPU-only inference. Expect 1–12 tokens/second depending on your CPU and the quantisation level. The 8B Q4 model runs on any modern desktop CPU with 8 GB RAM. It's usable for testing and low-volume use but too slow for production.
What is the difference between Llama 3 and Llama 3.1?
Llama 3.1 added a 405B parameter variant, extended context windows to 128K tokens (up from 8K), and improved instruction-following. The 8B and 70B variants in Llama 3.1 outperform their Llama 3 counterparts on most benchmarks. Use Llama 3.1 unless you have a specific reason to use the older version.
What is GGUF and why does it matter?
GGUF is the file format used by llama.cpp for quantised models. It packages model weights, tokeniser, and metadata into a single file. Quantisation (Q4, Q5, Q8) reduces model size and memory usage at a small quality cost. Q4_K_M is the recommended default — it cuts the 8B model from 16 GB (fp16) to 4.7 GB with minimal quality loss.
How do I use a local Llama model with my existing OpenAI code?
Both Ollama and llama.cpp server expose an OpenAI-compatible API. Change your base URL to http://localhost:11434/v1 (Ollama) or http://localhost:8080/v1 (llama.cpp), set any non-empty string as the API key, and change the model name to the local model name. No other code changes needed.
Is Llama 3 free for commercial use?
Yes, under Meta's Llama 3 Community Licence. Commercial use is permitted for most companies. The main restriction is that companies with over 700 million monthly active users must request a separate licence from Meta. For the vast majority of businesses, Llama 3 is free to use commercially.

More guides

Was this guide useful?