Sub topic 2
What Ollama Does: A Local Server, a CLI, and a Model Store
This chapter assumes you are comfortable in a terminal, know basic HTTP and JSON, and have a general idea of what a large language model is. You do not need Ollama installed yet. The next chapter covers installation. Here you build the working model of what Ollama is made of, so the later commands make sense.
The three parts
Ollama is not a single program that you start, use, and close. It has three parts that work together.
- The server. A background process that listens on a local network port. It loads models into memory, runs inference (the step where a model turns input text into output text), and answers requests over HTTP.
- The CLI. The
ollamacommand. It does not run models itself. It is a thin client that sends requests to the server. - The model store. A directory on disk where downloaded models are kept as files, so each model is downloaded once and reused.
The most important idea is that the CLI and your own scripts are both clients of the same server. When you type ollama run llama3.2, the command talks to the server, and the server does the work. When your Python script calls the HTTP API, it talks to the same server in the same way.
The server
The server listens on 127.0.0.1 (also called localhost), port 11434. Binding to 127.0.0.1 means only programs on your own machine can reach it. Other computers on your network cannot, unless you change the host setting. A later chapter on server configuration explains how.
The server has several jobs:
- It exposes an HTTP API for generating text, chatting, producing embeddings, and managing models.
- It loads a model into memory the first time a request names it.
- It keeps that model in memory for a while after the last request, so the next request starts quickly. This is the keep-alive behavior.
- It unloads the model when it has been idle too long, which frees memory.
Because loading is lazy, the first request to a model is slower than later ones. The delay is the time to read the weights from disk into memory. This is normal and not a sign of a problem.
You can check that the server is up with a plain HTTP request:
curl http://localhost:11434/A running server replies with the text Ollama is running. If the connection is refused, the server is not running, and no CLI command that needs a model will work.
The CLI
The ollama command has two kinds of subcommands.
| Kind | Examples | What happens |
|---|---|---|
| Talks to a running server | `run`, `pull`, `list`, `ps`, `show`, `rm`, `create` | Sends HTTP requests to the server and prints the result |
| Starts the server | `serve` | Runs the server process in your terminal |
Most of the time you do not call ollama serve yourself. The installer on most systems sets up the server to start automatically in the background. If it is not running, you can start it by hand in a separate terminal.
Here are the CLI commands from the topic's example set, with the role each one plays:
ollama pull llama3.2
ollama run llama3.2
ollama list
ollama ps
ollama show llama3.2
ollama rm llama3.2pulldownloads a model into the model store.runopens an interactive chat. If the model is not in the store yet, it pulls it first.listshows models in the store, meaning the models on disk.psshows models currently loaded in memory.showprints details about one model, such as its parameters and template.rmdeletes a model from the store.
Notice the difference between list and ps. A model can be on disk without being in memory, and that is the usual state of most models. Confusing the two is a common source of questions such as "I pulled the model, so why does ollama ps show nothing?" The answer is that nothing has asked the server to load it yet, or it has already been unloaded after sitting idle.
The model store
The model store is a directory where Ollama keeps everything it downloads. Its default location depends on how you installed Ollama.
| Platform | Typical default location |
|---|---|
| macOS | `~/.ollama/models` |
| Linux (installed as a system service) | `/usr/share/ollama/.ollama/models` |
| Windows | `C:\Users\<you>\.ollama\models` |
Treat these as typical rather than guaranteed. The location can differ by version and install method, and you can move it with the OLLAMA_MODELS environment variable, which a later chapter covers.
Layers and sharing
Ollama stores models in a layered format that resembles how container images are organized. A model is a small manifest (a list of parts) plus several blobs (the actual data files). The blobs are named by a hash of their contents. Typical parts include:
- the model weights, which are the large numeric tables that hold what the model learned,
- the prompt template, which says how to wrap messages before the model sees them,
- parameters such as default temperature or context size,
- an optional system prompt.
Because blobs are named by content, two models that share the same weights share one file on disk. This matters when you create a customized model later with a Modelfile. A custom model built FROM llama3.2 adds a small manifest and a few small blobs. It does not copy several gigabytes of weights again.
It also means ollama rm only frees disk space for blobs that no other model still uses.
Why models are large
A model file holds billions of numbers. Even compressed, a small model is often around 2 GB and a mid-sized one is often 4 to 10 GB or more. Plan disk space accordingly, especially if you try many models. Chapters later in this tutorial explain how size relates to parameter count and quantization.
A request from start to finish
Follow one ollama run llama3.2 command to see how the parts cooperate.
In words:
- The CLI sends a request to the server.
- The server checks the model store. If the model is missing, it downloads it from the Ollama registry, an online library of models, and saves it.
- The server loads the model into RAM or GPU memory.
- The server generates the reply and streams it back in pieces. The CLI prints each piece as it arrives.
- The model stays in memory until the keep-alive time passes without a new request.
On the second run of the same command, steps 2 and 3 are skipped if the model is still in memory. If it was unloaded, only the disk read in step 3 happens again.
Why this structure matters in practice
Knowing the three parts helps you predict behavior and debug it.
- One server, many clients. A terminal chat, a script, and a code editor plugin can all use the same loaded model. They do not each load their own copy.
- Shared memory budget. Because the server decides what to load, several large models requested at once compete for the same memory. The server may unload one model to make room for another, which causes a slow reload on the next request.
- Errors come from the server. When a CLI command fails with a connection error, the cause is almost always that the server is not running or is listening somewhere else. When it fails with a model error, the server is running and the problem is the model or the memory.
- Disk and memory are separate budgets. Disk space limits how many models you can keep. RAM or GPU memory limits which model you can run at one time.
Common mistakes
- Assuming
ollama runis the program that runs the model. It is only a client. Stopping the CLI does not stop the server or unload the model. - Reading
ollama listas "what is loaded." It lists what is on disk. Useollama psfor what is in memory. - Treating the first slow reply as a bug. The first request pays the loading cost.
- Expecting
ollama rmto always free the full model size. Shared blobs stay until no model references them. - Starting a second server by hand while one already runs. The second process cannot bind to the same port and exits with an error about the address being in use.
Exercise
You ran ollama pull llama3.2 an hour ago and have not used the model since. ollama list shows llama3.2, but ollama ps shows an empty list. Is something wrong? Explain using the three parts of Ollama.
Show answer
Nothing is wrong. ollama list reports the model store on disk, where llama3.2 was saved by the pull. ollama ps reports models the server holds in memory. A pull only downloads files, and the server loads a model lazily when a request names it, then unloads it after the keep-alive time passes without use. The next ollama run llama3.2 will load it again, with a short delay for reading the weights from disk.
Exercise
You create a custom model with FROM llama3.2 in a Modelfile, then run ollama rm llama3.2. Does the custom model lose its weights? Why or why not?
Show answer
Removing the base model's name does not necessarily delete the shared weight blob, because blobs are stored by content hash and are only removed when no model still references them. The custom model's manifest still points to the same weights blob, so it keeps working. Disk space is freed only for blobs that no remaining model uses.