Ollama Command Complete Manual
This chapter introduces Ollama-related commands, covering installation, model management, run parameters, Modelfile, REST API, environment variables, and common troubleshooting, all organized based on Ollama 0.17.x.
Installation and Startup
Each of the three platforms has a standard installation method; after installation, Ollama automatically runs as a background service, listening on 127.0.0.1:11434。
| Platform | Installation method | Description |
|---|---|---|
| macOS | brew install ollama | You can also download the dmg installer from the official website |
| Linux | curl -fsSL https://ollama.com/install.sh | sh | Official one-click script that automatically configures the systemd service |
| Windows | Download the installer from the official website | Install via the wizard, automatically registered as a system service |
| Docker | docker run -d -v ollama:/root/.ollama -p 11434:11434 ollama/ollama | The data volume ollama persists models |
In the vast majority of scenarios you do not need to start the service manually, but it is used for troubleshooting and temporary configuration changes ollama serve。
Example
Start the service in the foreground, with logs printed directly to the terminal, most commonly used for troubleshooting
ollama serve
Verify the service is ready: returning "Ollama is running" means normal
curl http:
//
localhost:
11434
If you are prompted that the port is occupied, it means the background service is already running. In this case, opening another terminal and running ollama serve will produce an error, which is normal; just use the command line or API directly.
Complete Table of Model Management Commands
Model management is the main body of the Ollama command line, with about ten commands, all listed in the table below.
| Command | Function | Example |
|---|---|---|
| ollama pull |
Download a model from the model library; without a tag, latest is pulled by default | ollama pull qwen3.5:4b |
| ollama run |
Run a model interactively; if not present locally, it will be pulled automatically | ollama run qwen3.5 |
| ollama list / ollama ls | List local models, sizes, and modification times | ollama list |
| ollama show |
View model details: parameters, template, system prompt, etc. | ollama show qwen3.5 |
| ollama ps | View models loaded into memory and remaining lifetime | ollama ps |
| ollama stop |
Immediately stop and unload a running model | ollama stop qwen3.5 |
| ollama cp
|
Copy or rename a model | ollama cp qwen3.5 runoob-clone |
| ollama rm |
Delete a local model to free disk space | ollama rm qwen3.5:0.8b |
| ollama create
|
Create a custom model based on a Modelfile | ollama create runoob-coder -f Modelfile |
| ollama push |
Push a model to a remote model library; login required first | ollama push myteam/runoob-coder |
| ollama serve | Start the background service, usually runs automatically with the system | ollama serve |
The most frequently used combination in daily use is the four: run, list, ps, rm: run models, check inventory, view memory, free space.
Example
Download a model of a specified specification
ollama pull qwen3.5:0.8b
Copy one and give it your own name
ollama
cp
qwen3.5 runoob-clone
After confirming the copy succeeded, delete the specification no longer needed
ollama
rm
qwen3.5:0.8b
rm deletes the model file corresponding to that tag; if other tags share the same underlying weights (blobs), disk space will only be truly released after the last tag referencing it is deleted.
The run Command and Interactive Mode
run can serve as a one-time Q&A tool, enter the interactive mode of multi-turn conversation, and also supports changing parameters at runtime.
Command-Line Arguments
Parameters are written after the model name, take effect only for this run, and are not written into the model configuration.
Example
Interactive conversation
ollama run qwen3.5
Single Q&A: the prompt follows the model name, and it exits automatically after answering
ollama run qwen3.5
"Introduce runoob Runoob Tutorial in one sentence"
Display token statistics: performance metrics such as total time and tokens per second
ollama run qwen3.5
--verbose
Force the model to output in JSON format
ollama run qwen3.5
--format
json
Increase the context window (unit: token)
ollama run qwen3.5
--num-ctx
8192
Put as many model layers as possible into the GPU (999 means no limit)
ollama run qwen3.5
--num-gpu
999
Slash Commands in Interactive Mode
After entering interactive mode, commands starting with a slash are used to adjust session state, and these adjustments only take effect for the current session.
| Command | Function |
|---|---|
| /set parameter
|
Temporarily adjust inference parameters, such as temperature |
| /set system |
Temporarily set the system prompt |
| /show info | Display current model information |
| /show modelfile | Display the Modelfile corresponding to the current model |
| /save |
Save the current session's settings as a new model |
| /load |
Load a saved model or session |
| /clear | Clear the current conversation context and start over |
| /bye | Exit interactive mode |
To keep parameters adjusted by slash commands long-term, use /save to save them as a new model; behind the scenes it generates a Modelfile for you.
Another shortcut to exit interactive mode is pressing Ctrl+D, which has the same effect as /bye.
Modelfile Custom Models
Modelfile uses a Dockerfile-like syntax to package "base model + parameters + system prompt" into a new model.
Example
File path: Modelfile
FROM specifies the base model (required), which can also be a local GGUF file path
FROM qwen3.5
Common inference parameters (optional)
PARAMETER temperature
0.2
PARAMETER num_ctx
8192
System prompt, which determines the model's role and behavior (optional)
SYSTEM You are a senior Python engineer; output concise, type-annotated, testable code.
Example
Build a new model with a Modelfile
ollama create runoob-coder
-f
Modelfile
Run it like a normal model
ollama run runoob-coder
"Write a quicksort, with tests"
To import local GGUF weights you only need to point FROM to the file path, commonly used to run model files downloaded from the open-source community.
Example
File path: Modelfile
FROM points to a local GGUF weights file
FROM .
/
model-file.gguf
All Modelfile instructions are listed in the table below; the first three rows are the most commonly used combination.
| Instruction | Purpose | Required |
|---|---|---|
| FROM | Specify the base model or GGUF file path | Required |
| PARAMETER | Set inference parameters: temperature, num_ctx, top_p, stop, etc. | Optional |
| SYSTEM | Set the system prompt | Optional |
| TEMPLATE | Customize the conversation prompt template | Optional |
| ADAPTER | Load a LoRA adapter | Optional |
| MESSAGE | Preset conversation examples to achieve few-shot guidance | Optional |
| LICENSE | Declare the model license | Optional |
If you want to modify an existing model without writing from scratch, first run ollama show --modelfile 模型名 to export the complete recipe, then just create after making changes.
REST API Quick Reference
After the Ollama service starts, it listens by default on http://localhost:11434, and everything the CLI can do, the API can do too.
| Endpoint | Method | Function |
|---|---|---|
| /api/generate | POST | Single-turn text generation, streaming by default |
| /api/chat | POST | Multi-turn conversation, passing history via the messages array |
| /api/embed | POST | Generate text vector embeddings for RAG retrieval |
| /api/tags | GET | List local models, corresponding to ollama list |
| /api/show | POST | View model details, corresponding to ollama show |
| /api/pull | POST | Pull a model, corresponding to ollama pull |
| /api/delete | DELETE | Delete a model, corresponding to ollama rm |
Example
Single-turn generation (streaming)
curl http:
//
localhost:
11434
/
api
/
generate
-d
'{
"model": "qwen3.5",
"prompt": "Write a Hello World in Python"
}'
Multi-turn conversation
curl http:
//
localhost:
11434
/
api
/
chat
-d
'{
"model": "qwen3.5",
"messages": [{"role": "user", "content": "Explain what a REST API is"}]
}'
Generate vector embeddings
curl http:
//
localhost:
11434
/
api
/
embed
-d
'{
"model": "nomic-embed-text",
"input": "your text content"
}'
List local models
curl http:
//
localhost:
11434
/
api
/
tags
View model details
curl http:
//
localhost:
11434
/
api
/
show
-d
'{"model": "qwen3.5"}'
Delete a model
curl
-X
DELETE http:
//
localhost:
11434
/
api
/
delete
-d
'{"model": "qwen3.5"}'
OpenAI-Compatible Interface
Ollama provides an OpenAI-compatible endpoint /v1/chat/completions, so existing code in the OpenAI ecosystem can be used directly by pointing base_url to the local address.
Example
File path: openai_compat.py
from
openai
import
OpenAI
base_url points to local Ollama; api_key can be any non-empty string
client
=
OpenAI
(
base_url
=
"http://localhost:11434/v1"
,
api_key
=
"ollama"
)
resp
=
client.
chat
.
completions
.
create
(
model
=
"qwen3.5"
,
Name of a model already downloaded locally
messages
=
[
{
"role"
:
"user"
,
"content"
:
"Hello, please introduce runoob"
}
]
,
)
(
resp.
choices
[
0
]
.
message
.
content
)
$ python3 openai_compat.py
你好!runoob(Runoob Tutorial)是一个面向初学者的编程学习网站,提供大量免费的基础技术教程。
Environment Variable Quick Reference
Environment variables are the main way to configure Ollama service behavior; after changing them, you need to restart the service for changes to take effect.
| Variables | Description | Default value |
|---|---|---|
| OLLAMA_HOST | Service listening address; 0.0.0.0 means allow LAN access | 127.0.0.1:11434 |
| OLLAMA_MODELS | Model storage path, commonly used when switching to a larger disk | ~/.ollama/models |
| OLLAMA_NUM_GPU | Number of model layers offloaded to the GPU; 999 means all | automatically |
| OLLAMA_NUM_PARALLEL | Number of concurrent requests for the same model | automatically |
| OLLAMA_MAX_LOADED_MODELS | Maximum number of models resident in memory at the same time | automatically |
| OLLAMA_FLASH_ATTENTION | Enable Flash Attention, recommended for long contexts | Close |
| OLLAMA_KEEP_ALIVE | How long a model stays idle before being unloaded from memory | 5m |
| OLLAMA_DEBUG | Enable debug logging to output more detailed runtime information | Close |
Example
Allow LAN access + move models to the data disk
export
OLLAMA_HOST
=0.0.0.0:
11434
export
OLLAMA_MODELS
=
/
data
/
ollama-models
ollama serve
OLLAMA_KEEP_ALIVE set to 0 means unloading the model immediately after each request, saving memory but requiring a reload on every request; set it to -1 to keep the model resident. The syntax of this value varies by version; refer to ollama serve --help and the official documentation.
Troubleshooting common problems
When encountering errors, first locate them using the table below; most problems fall into three categories: "wrong model name, service not running, insufficient resources".
| Problem | Troubleshooting approach |
|---|---|
| Insufficient VRAM / memory (OOM) | Use a smaller model size or lower quantization precision, e.g. 4b instead of 9b |
| Error message "model not found" | Check that the model name and tag are correct; tags are separated by a colon, e.g. qwen3.5:4b not qwen3.5-4b |
| connection refused | Confirm whether the service is running and check whether port 11434 is occupied |
| Slow response | Use ollama ps to check the PROCESSOR column and confirm the model is actually running on the GPU; appropriately reduce num_ctx |
| Confusion between multiple model versions | When no tag is specified, the "latest" version is chosen by internal rules; it is recommended to always explicitly specify the full tag |
One-line quick reference table
Finally, compress the most frequently used commands into a table, ready to copy and use.
| Command | Function |
|---|---|
| ollama pull |
Download a model |
| ollama run |
Run a model / enter interactive chat |
| ollama list | List downloaded models |
| ollama show |
View model details |
| ollama ps | List running models |
| ollama stop |
Stop and unload a model |
| ollama rm |
Delete a model |
| ollama cp
|
Copy / rename a model |
| ollama create |
Create a custom model with a Modelfile |
| ollama serve | Start the service |
Ollama updates quickly; some parameters and command behaviors may change between versions; before proceeding, refer to ollama --help and the official documentation.