How to Run an LLM Locally: Ollama and LM Studio Tutorial
Run an LLM locally step by step with Ollama or LM Studio: RAM and VRAM requirements, choosing and quantizing models, context length, and calling your local model through an OpenAI-compatible API.
Prerequisites
- •A computer with at least 8 GB of RAM (16 GB or a GPU recommended)
- •Basic command-line familiarity
- •Python 3.9+ for the API examples (optional)
What You'll Learn
- Estimate how much RAM or VRAM a model needs and pick a quantization
- Install Ollama, run models and manage them from the CLI
- Run models in LM Studio and start its local server
- Call a local LLM from Python through an OpenAI-compatible endpoint
- Increase context length and keep a local API secure
Running a large language model on your own computer used to mean compiling C++ and hunting for model weights. In 2026 it takes a few minutes: install Ollama or LM Studio, download a model, and you have a private, offline chatbot plus an OpenAI-compatible API on localhost. This tutorial shows how to run an LLM locally step by step, how much RAM and VRAM you need, which models to start with, and how to call your local model from code.
Why run an LLM locally?
The trade-off is quality and speed. Open-weight models that fit on a laptop are very capable for summarising, drafting, coding help and retrieval-augmented generation, but the largest hosted frontier models are still stronger on hard reasoning and long agentic tasks. If you are new to the terminology, read what an LLM is first.
How much RAM and VRAM do you need?
Model size is measured in parameters, and local tools run quantized models, usually 4-bit, to save memory. A useful rule of thumb for 4-bit (Q4) models is about 0.6 GB of memory per billion parameters, plus 1 to 4 GB for the context window (the KV cache), which grows with longer prompts.
On Apple Silicon, the GPU shares unified memory with the system, so a 32 GB Mac can dedicate roughly two thirds of it to a model. On PCs, NVIDIA GPUs with CUDA are the best supported, and AMD GPUs work through ROCm or Vulkan in most tools. Without a GPU, models still run on the CPU from system RAM, just more slowly. As a rough guide, 10 or more tokens per second feels interactive for chat.
Quantization labels you will see:
Option 1: run an LLM locally with Ollama
Ollama is a free, open source tool that downloads, runs and serves models with one command. It has desktop apps for macOS and Windows and a one-line installer for Linux.
Install Ollama
On macOS or Windows, download the app from ollama.com. On Linux, run:
curl -fsSL https://ollama.com/install.sh | sh
ollama --versionRun your first model
ollama run llama3.2:3bThe first run downloads the model (about 2 GB), then drops you into a chat prompt. Type a question, and use /bye to exit. Model names follow the pattern name:tag, where the tag usually encodes the size. Tags change as new models are released, so browse ollama.com/library and pick a model that fits your memory. Good starting points are a 3B to 4B model for low-end machines, a 7B to 9B general model such as a Qwen, Llama, Gemma or Mistral variant for 8 GB GPUs, and a dedicated coding model if you mainly want programming help.
The everyday commands:
ollama pull qwen3:8b
ollama list
ollama ps
ollama show qwen3:8b
ollama rm llama3.2:3bollama ps shows which models are loaded and whether they run on the GPU or the CPU. If you see a CPU percentage when you expected GPU, the model is too large for your VRAM; choose a smaller model or a lower quantization.
Increase the context window
Small default context windows are the most common cause of a local model "forgetting" the start of a long document. Set a larger default for the server with an environment variable, keeping in mind that more context uses more memory:
OLLAMA_CONTEXT_LENGTH=16384 ollama serveOr bake settings into your own model variant with a Modelfile:
FROM qwen3:8b
PARAMETER num_ctx 16384
PARAMETER temperature 0.3
SYSTEM You are a concise senior software engineer. Answer with code first.ollama create code-helper -f Modelfile
ollama run code-helperCall Ollama from code
Ollama serves an HTTP API on port 11434. Its native chat endpoint looks like this:
curl http://localhost:11434/api/chat -d '{
"model": "qwen3:8b",
"messages": [{"role": "user", "content": "Explain a race condition in two sentences."}],
"stream": false
}'It also exposes an OpenAI-compatible endpoint under /v1, so existing OpenAI SDK code works by changing the base URL. Install the SDK with pip install openai, then:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
completion = client.chat.completions.create(
model="qwen3:8b",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Write a Python function that reverses a string."},
],
)
print(completion.choices[0].message.content)The API key is ignored by Ollama but required by the SDK. This makes it easy to develop against a local model and switch to a hosted one later. See the OpenAI API in Python tutorial for the hosted side.
Option 2: run an LLM locally with LM Studio
LM Studio is a free desktop app for macOS, Windows and Linux with a graphical interface, which makes it the easiest way to try local models if you prefer not to use a terminal.
To use the model from code, open the Developer tab and start the local server. It listens on port 1234 with OpenAI-compatible endpoints, so the Python example above works with base_url set to http://localhost:1234/v1. LM Studio also ships a CLI called lms:
lms get qwen3-8b
lms load qwen3-8b
lms server start
lms psOllama vs LM Studio: which should you use?
Our Ollama vs vLLM vs LM Studio comparison goes deeper into performance and deployment trade-offs.
Performance and security tips
Next steps
Once a local model is running, the natural next projects are a private document chat using retrieval-augmented generation, a local coding assistant in your editor, or an agent built with the LangChain tutorial, which works with local models through the langchain-ollama integration. Because both Ollama and LM Studio speak the OpenAI API format, almost any tool that supports a custom OpenAI base URL can use your local LLM.

