Necessary Ollama Commands
Necessary Commands for Running Ollama locally.
The Ultimate Cheat Sheet: Common Ollama Commands for Local LLMs
Running Large Language Models (LLMs) locally has never been easier thanks to Ollama. Whether you are running a lightweight model or utilizing a high-end GPU like an RTX 4090, managing your local environment efficiently requires knowing the right commands.
Here is a complete breakdown of all the necessary Ollama commands, categorized for quick reference.
1. Installation & Service Management
The native Linux installer configures Ollama as a background system service (systemd). You rarely need to launch the server manually, but managing the underlying service is crucial when troubleshooting or updating environment variables.
Install or update Ollama
curl -fsSL https://ollama.com/install.sh | sh
Downloads and executes the official automated installation script for Linux systems. This also updates Ollama to the latest version if it is already installed.
Check service status
systemctl status ollama
Checks if the background Ollama daemon is currently running, stopped, or experiencing errors.
Restart the service
sudo systemctl restart ollama
Restarts the service. This is required if you apply system-level changes, update environment variables, or need to forcefully flush stuck models out of memory.
Stop the service
sudo systemctl stop ollama
Shuts down the Ollama background process completely, freeing up system resources.
2. Model Management
Ollama uses a syntax heavily inspired by Docker to manage model weights downloaded to your local disk.
Pull a model
ollama pull <model_name>
Downloads a model directly from the official Ollama registry without launching an active session.
# Example
ollama pull llama3.2
List downloaded models
ollama list
# or
ollama ls
Lists all LLMs currently downloaded and available on your local hard drive, along with their sizes and unique IDs.
Remove a model
ollama rm <model_name>
Permanently deletes a specific model from your local storage to free up disk space.
# Example
ollama rm gemma2
Show model details
ollama show <model_name>
Displays metadata about a downloaded model, including its architecture type, system prompt rules, parameters, and default context window limitations.
Copy a model
ollama cp <source_model> <new_model>
Creates a duplicate copy of a local model under a new name. This is highly useful before modifying a model's default configuration parameters.
3. Interacting with Models (Inference)
These are the daily-driver commands used to send prompts to your local models.
Start an interactive chat
ollama run <model_name>
Initializes an interactive, multi-turn chat session directly inside your terminal window. If the model is not already downloaded, Ollama automatically pulls it first.
Run a one-shot prompt
ollama run <model_name> "<your_prompt>"
Executes a single prompt immediately from the command line. It prints the output directly to the terminal and exits without entering an interactive loop.
# Example
ollama run llama3.2 "Write a quick Python sorting function"
Pipe a file into a model
cat <file> | ollama run <model_name> "<instruction>"
Pipes the text contents of a local file directly into the model. This is perfect for parsing logs, summarizing long documentation, or analyzing scripts.
# Example
cat error.log | ollama run llama3.2 "Explain this error"
Essential in-chat slash commands
When you are inside an active interactive session (ollama run), use these internal slash commands to control the context:
| Command | Description |
|---|---|
/clear |
Wipes the active conversation history to clear the model's short-term memory. |
/set parameter num_ctx <value> |
Changes the model's active context window size dynamically during a session (e.g., /set parameter num_ctx 8192). |
/show system |
Displays the active system prompt managing the model's current behavior. |
/bye |
Safely terminates the chat session and returns you to your standard terminal. |
4. System & VRAM Monitoring
Managing video memory (VRAM) usage is critical if you share your machine's graphics card with gaming, video editing, or other development workflows.
List models loaded in memory
ollama ps
Displays which models are currently loaded and active in your system's VRAM, how much space they are occupying, and how long they will remain cached before automatic offloading.
Unload a model from VRAM
ollama stop <model_name>
Forcefully unloads a specific model from your GPU's VRAM. This instantly frees up your graphics memory without deleting the model file from your storage.
5. Creating Custom Models
Ollama lets you build customized system variants using a blueprint configuration file called a Modelfile.
Create a custom model
ollama create <custom_name> -f ./Modelfile
Compiles and saves a brand new local model variant using the rules, system parameters, and base weights outlined in a specific path Modelfile.