How to Run Local AI Models on Linux with Ollama: A Complete Step-by-Step Guide

By LinuxCert.Guru Team·

Objective

This guide shows you how to install Ollama on Linux, download your first AI model, and run it entirely on your own machine with no cloud connection, no API fees, and no data leaving your computer. By the end, you will have a working local AI you can use for coding, writing, document analysis, and automation, completely private and completely free to run.

The Problem with Cloud AI Services

Every time you use ChatGPT, Claude, or any cloud-based AI tool, your input goes to a remote server. Your code, your documents, your questions, your private business information, all of it leaves your machine. You pay either with money (API fees that add up fast) or with your data (which trains their models). For anyone working with sensitive material or simply valuing privacy, that is a real problem.

Ollama solves this. It lets you run powerful AI models on your own Linux machine, locally, offline after the initial download, and at zero ongoing cost.

Feature Cloud AI (ChatGPT, Claude) Local AI with Ollama
Cost $20 to $200+ per month depending on usage Free after hardware you already own
Privacy Your prompts go to remote servers Everything stays on your machine
Internet required Yes, always Only for the initial model download
Data ownership Vendor terms apply You own everything
Customization Limited by what the provider allows Full control over model and parameters
Offline use No Yes, once the model is downloaded
API integration Remote API with rate limits and costs Local REST API, no limits

What Is Ollama

Ollama is a lightweight open-source tool that makes downloading, managing, and running large language models on your local machine as simple as a few terminal commands. Instead of configuring complex machine learning environments, setting up Python dependencies, or wrestling with model formats, Ollama handles all of that underneath. You just tell it which model you want and start talking to it.

All processing happens on your hardware. Your prompts never leave the machine. The model runs in memory and responds directly in your terminal or through a local API that your own applications can call.

How the Process Works

  • Step 1: Install Ollama on your Linux system with a single command
  • Step 2: Pull a model from Ollama's library (downloaded once, stored locally)
  • Step 3: Run the model in your terminal or call it via the local REST API
  • Step 4: Use it offline for anything: coding help, writing, analysis, automation

Supported AI Models

Ollama supports a wide range of open-weight models. Here are the most popular ones and what each is best at:

Model Best For Size (approx.) RAM Needed
llama3 General purpose, reasoning, writing 4.7 GB 8 GB+
mistral Fast responses, instruction following 4.1 GB 8 GB+
codellama Code generation, debugging, code review 3.8 GB 8 GB+
gemma2 Lightweight general use, older hardware 1.6 GB 4 GB+
phi3 Fast, efficient, low-resource systems 2.2 GB 4 GB+
qwen2 Multilingual tasks, Chinese and English 4.4 GB 8 GB+
deepseek-coder Code-specific tasks, technical documentation 3.8 GB 8 GB+

Start with llama3 or mistral for general use. If your machine has only 4 to 6 GB RAM, use gemma2 or phi3 instead, they are smaller but still capable for most everyday tasks.

Prerequisites

Before installing, confirm your system meets these requirements:

Requirement Minimum Recommended
Linux distribution Ubuntu 20.04, Debian 11, Fedora 38, or equivalent Latest LTS release
RAM 8 GB 16 GB or more for larger models
Storage 20 GB free space 50 GB+ if you plan to use multiple models
Storage type HDD works SSD for faster model loading
GPU (optional) Not required NVIDIA (CUDA) or AMD (ROCm) for faster inference
Internet Required for initial install and model download only Stable broadband for faster model download
Terminal access Required Basic command-line familiarity helpful
sudo access Required for installation Required

No GPU is required. Ollama runs fine on CPU-only machines. A GPU speeds up inference significantly if you have one, but it is not a barrier to getting started.

Step 1: Install Ollama

Update your system first, then install Ollama using the official script:

# Update system packages first
sudo apt update && sudo apt upgrade -y

# Install Ollama with the official one-line installer
curl -fsSL https://ollama.com/install.sh | sh

# Verify the installation
ollama --version

If the version number prints successfully, for example ollama version 0.x.x, the installation worked. If the Ollama service doesn't start automatically, start it manually:

# Start the Ollama server manually if needed
ollama serve

Leave this running in one terminal and open a second terminal to run your models.

Step 2: Download and Run Your First Model

This command downloads llama3 (if not already installed) and immediately starts an interactive chat session:

# Download and run llama3
ollama run llama3

The first run downloads the model, which is around 4.7 GB. Depending on your connection speed this takes a few minutes. After that, you'll see a prompt where you can type directly:

>>> Explain what a Docker container is in simple terms.

>>> Write a Python function to read a CSV file and return the column names.

>>> Summarize the key points of this text: [paste your text here]

>>> /bye

Type /bye or press Ctrl+D to exit the session. The model stays installed on your machine and loads instantly on future runs.

Step 3: Learn the Essential Commands

Command What It Does
ollama run llama3 Start an interactive chat session with the llama3 model
ollama pull mistral Download a model without starting a session
ollama list Show all models currently installed on your system
ollama rm llama3 Delete a model from your machine and free up disk space
ollama show llama3 Display model details: size, parameters, and configuration
ollama --version Show which version of Ollama is installed
ollama serve Start the Ollama server manually if it is not running
ollama ps Show which models are currently loaded in memory

Step 4: Use the Local REST API

Ollama runs a local REST API on port 11434. This lets you call the model from your own scripts, applications, and automation tools without going through the interactive terminal session:

# Send a prompt via curl (non-streaming response)
curl http://localhost:11434/api/generate \
  -d '{
    "model": "llama3",
    "prompt": "What is the difference between a process and a thread?",
    "stream": false
  }'
# Python example using the requests library
import requests

response = requests.post(
    "http://localhost:11434/api/generate",
    json={
        "model": "llama3",
        "prompt": "Summarize this in three bullet points: " + your_text,
        "stream": False
    }
)

print(response.json()["response"])

This is where Ollama becomes genuinely powerful for developers. You can build document summarizers, code review tools, automated report generators, internal chatbots, and any other AI-powered application, all calling your own local model over localhost with no API keys, no rate limits, and no charges per call.

What You Can Actually Build With This

Use Case How Ollama Helps Recommended Model
Code review Paste code into the terminal or API, ask for review and suggestions codellama or deepseek-coder
Document summarization Feed text into the API, get structured summaries automatically llama3 or mistral
Writing assistance Draft emails, reports, documentation, or blog posts llama3 or mistral
Internal chatbot Build a private chat interface for your team using the REST API llama3
Script automation Generate shell scripts, explain commands, debug errors codellama or llama3
Data analysis help Ask questions about data structures, SQL queries, pandas operations deepseek-coder or llama3
Multilingual tasks Translate, respond in multiple languages qwen2

Troubleshooting Common Issues

Problem Likely Cause Fix
ollama: command not found Installation path not in your shell's PATH Re-run the install script, then open a new terminal window
Model download is very slow Unstable internet or large model size Let it finish without interrupting, or try a smaller model like gemma2 or phi3
Out of memory error Model is larger than available RAM Use a smaller model, close background applications, or add more RAM
Ollama service not running Server stopped or was never started Run ollama serve in a separate terminal and leave it open
No space left on device Model files fill available storage Delete unused models with ollama rm modelname to free space
AI responses are very slow CPU-only inference on a large model Use a smaller model, or enable GPU acceleration if you have a compatible card
Permission denied Missing sudo privileges during install Run installation commands with sudo
Cannot connect to localhost:11434 Ollama server is not running Start with ollama serve then retry your API call

GPU Acceleration: Optional but Worth Knowing

If you have a compatible GPU, Ollama detects it automatically and uses it for inference. This makes responses significantly faster, especially for larger models.

  • NVIDIA GPUs: Ollama uses CUDA automatically if the NVIDIA drivers and CUDA toolkit are installed
    • Verify with: nvidia-smi (should show your GPU)
    • Install drivers: sudo apt install nvidia-driver-535 (version may vary)
  • AMD GPUs: Ollama uses ROCm for AMD GPU acceleration
    • ROCm support is improving but more limited than NVIDIA at this time
    • Check compatibility at rocm.docs.amd.com
  • No GPU: Ollama falls back to CPU inference automatically. It works, just slower. For most tasks on a modern CPU, the speed is entirely usable.

Quick Reference Card

Task Command
Install Ollama curl -fsSL https://ollama.com/install.sh | sh
Start the server ollama serve
Download and run a model ollama run llama3
Download only (no session) ollama pull mistral
List installed models ollama list
Remove a model ollama rm llama3
Check model details ollama show llama3
Call via API curl http://localhost:11434/api/generate -d '{"model":"llama3","prompt":"your question","stream":false}'
Exit a chat session /bye or Ctrl+D
Check Ollama version ollama --version

Conclusion

Ollama makes running a capable AI on your own Linux machine genuinely straightforward. One install command, one model download, and you have a private AI that costs nothing to run, works offline, and keeps every prompt on your own hardware.

  • No API fees, no subscriptions, no data leaving your machine
  • Works without a GPU, though a compatible GPU makes it faster
  • The local REST API lets you build real applications on top of it
  • Start with llama3 or mistral for general use, codellama for coding tasks, gemma2 if your machine has limited RAM
  • Most troubleshooting issues are straightforward: not enough RAM, service not running, or a PATH issue after install

The technology that was behind expensive API paywalls two years ago is now running on ordinary Linux machines for free. If you work with sensitive data, build tools that need AI capabilities, or simply want to stop paying for something your own hardware can do, Ollama is where to start.

 

$_
Ready to go beyond reading?Practice with free, auto-graded RHCSA labs.
Start free →