Building AI Agents and Tool-Calling Workflows / Start Here

Set up Ollama and the course model

Lesson 2 of 37. Open to read. No account needed.

What You Will Build

By the end of this lesson a model server will be running on your own computer, answering with the course model, granite4.1:3b, and you will know how to prove it. You will:

  • install Ollama and keep it reachable only from your own computer, with its cloud features switched off;
  • set and read environment variables for one terminal session;
  • pull the model and confirm you have the exact build the course was tested with;
  • read ollama ps and /api/version and say what each one proves;
  • diagnose the three setup failures learners meet most often.

Before you start, check your computer against this table. Allow about 45 minutes, plus download time: Ollama is about 0.2 GB on macOS and 1.5 to 1.7 GB on Windows and Linux, and the model is 2.1 GB.

Model output shown in this lesson is illustrative: the author's runs with granite4.1:3b on Ollama 0.40.7, with the settings in the code shown. Your wording, ids and times can differ; the text after each output says what should match.

RequirementSupported
macOS14 (Sonoma) or later on Apple silicon
Windows10 22H2 or later, or 11, on x64
Linuxx86_64 or arm64
MemoryAt least 8 GB; 16 GB recommended
Free diskAbout 10 GB for Ollama, the model and the course's files
Graphics card (GPU)Not required; Ollama uses a supported one if present

The course was tested with Ollama 0.40.7, released on 18 October 2026. Ollama updates often; a newer version should work, and the lessons say which version produced each recorded output.

How the Pieces Fit

Architecture map of the learner's computer. Inside one boundary labelled "your computer": the terminal, where you type ollama commands; your Python programs, which send HTTP requests with httpx; the Ollama server, listening on 127.0.0.1:11434; the model files for granite4.1:3b on disk; and the processor, CPU or GPU, that runs the model. Arrows go from the terminal and from Python to the server, from the server to the model files, and from the server to the processor. Outside the boundary, two connections are crossed out: Ollama's cloud models and web search, switched off by local-only mode, and other computers on the network, which cannot connect because the server listens only on 127.0.0.1.

Everything the course runs stays inside your computer.

The Ollama server is the centre of the setup. It is a program that loads the model into memory and answers HTTP requests at one address, 127.0.0.1:11434. 127.0.0.1 means "this computer": requests can come only from programs running on the same machine. Two kinds of program talk to it:

  • the ollama command in your terminal, which you use to pull, list and inspect models;
  • your Python programs, which from the next lessons onwards send chat requests with httpx.

Both are clients of the same server. When the server is not running, both fail in the same way, which is useful when diagnosing problems. The server reads the model files from disk (on macOS and Windows under the .ollama folder in your home folder) and runs the model on the GPU if it can, or the CPU otherwise. The two crossed-out paths are the subject of Step 2.

Step 1: Install Ollama

macOS. Download Ollama.dmg from ollama.com/download or from the v0.40.7 release page, open it and drag Ollama into the Applications folder. Start Ollama from Applications. On first start it asks permission to link the ollama command into /usr/local/bin; allow it, so the command works in a terminal. Ollama then runs in the menu bar.

Windows. Download and run OllamaSetup.exe from the same places. It needs no administrator rights. Ollama starts in the taskbar's notification area, and the ollama command works in a new PowerShell window.

Linux. Ollama's install script installs a chosen version and sets it up as a background service. Download it, read it, then run it:

curl -fsSL https://ollama.com/install.sh -o install-ollama.sh
less install-ollama.sh
OLLAMA_VERSION=0.40.7 sh install-ollama.sh

The script asks for your password because it installs into system folders and creates an ollama service account. Reading a script before running it with administrator rights is a habit worth keeping.

On every system, open a new terminal and check the version:

ollama -v
ollama version is 0.40.7

If the command is not found, the terminal was opened before the installation finished, or (on macOS) the link into /usr/local/bin was not allowed: open Ollama again from Applications and accept the prompt.

Bridge: Environment Variables for One Session

Many programs, Ollama included, read settings from environment variables: named text values that a program receives from the terminal that starts it. A variable you set in a terminal lasts until that terminal closes, and every program started from that terminal inherits it. A new terminal starts without it.

Try it with a harmless name. In bash or zsh (macOS and Linux):

export COURSE_TEST=hello
echo "$COURSE_TEST"

In PowerShell (Windows):

$Env:COURSE_TEST = 'hello'
$Env:COURSE_TEST

Both print hello. Now open a second terminal window and print the variable again: it is empty there (bash and zsh print a blank line; PowerShell prints nothing). To remove it from the first terminal, use unset COURSE_TEST or Remove-Item Env:COURSE_TEST.

The variable this course meets first is OLLAMA_HOST: the address of the server. The ollama command and every course program read it, and when it is not set they use 127.0.0.1:11434. You normally leave it unset. If a command cannot reach the server, check that it is not set to something else:

echo "$OLLAMA_HOST"
$Env:OLLAMA_HOST

One limit matters here. A variable set in a terminal reaches programs you start from that terminal, not programs that were already running. The Ollama server is started by the Ollama app or, on Linux, by the system's service manager, so a variable you type in a terminal does not change the server. The next step therefore uses a settings file instead.

Step 2: Keep the Server Local

Two settings keep everything the course runs on your computer.

The address. Ollama listens on 127.0.0.1:11434 by default, so programs on other computers cannot connect to it. Its documentation shows how to make it listen on the network with OLLAMA_HOST=0.0.0.0; the course never does this, and you should not either while practising: anyone on the same network could then use your model server.

Local-only mode. Ollama can also run models on Ollama's own cloud service and search the web, and those features send prompts off your computer. The course uses neither, so switch them off. On macOS and Windows, create a file called server.json in the .ollama folder in your home folder, containing:

{
  "disable_ollama_cloud": true
}

On macOS (or Linux without the service), from a terminal:

mkdir -p ~/.ollama
printf '{\n  "disable_ollama_cloud": true\n}\n' > ~/.ollama/server.json

On Windows, in PowerShell:

New-Item -ItemType Directory -Force "$HOME\.ollama" | Out-Null
Set-Content -Path "$HOME\.ollama\server.json" -Value '{ "disable_ollama_cloud": true }'

Then quit Ollama from the menu bar or taskbar and start it again, because the server reads the file when it starts.

On Linux the service runs under its own account, so set the equivalent environment variable on the service instead:

sudo systemctl edit ollama.service

In the editor that opens, add these two lines, then save and close:

[Service]
Environment="OLLAMA_NO_CLOUD=1"
sudo systemctl daemon-reload
sudo systemctl restart ollama

Confirm the setting from the server's log, which records it at start-up. On macOS:

grep "cloud disabled" ~/.ollama/logs/server.log

On Linux:

journalctl -u ollama --no-pager | grep "cloud disabled"

On Windows:

Select-String -Path "$Env:LOCALAPPDATA\Ollama\server.log" -Pattern "cloud disabled"

The line you are looking for ends with msg="Ollama cloud disabled: true". The log keeps earlier start-ups too, so look at the last matching line.

Step 3: Pull the Model

Pulling downloads a model's files from Ollama's model library and checks them. Pull the course model once:

ollama pull granite4.1:3b

The name has two parts. granite4.1 is the model, Granite 4.1 from IBM; 3b is the tag, here the version with about 3 billion parameters (the numbers the model learned in training). The download is only 2.1 GB because each parameter is stored in four to five bits instead of sixteen, a compression called quantisation (Q4_K_M in the output below). The model is published under the Apache 2.0 licence, which allows the use this course makes of it. The last lines of the pull show it checking what it downloaded:

verifying sha256 digest
writing manifest
success

Now list the models on the server:

ollama list
NAME             ID              SIZE      MODIFIED
granite4.1:3b    6fd349357287    2.1 GB    Less than a second ago

The ID is the start of the model's digest, a fingerprint computed from its files. If yours is 6fd349357287, you have exactly the build the course was tested with. A different ID means the library now serves a different build under the same name; the course should still work, but recorded outputs may differ more than usual.

ollama show describes the model:

ollama show granite4.1:3b
  Model
    architecture        granite
    parameters          3.4B
    context length      131072
    embedding length    2560
    quantization        Q4_K_M
    template source     go_template

  Capabilities
    completion
    tools

  License
    Apache License
    Version 2.0, January 2004
    ...

Two lines matter for this course. tools under Capabilities means the model was trained to ask for tools, which every agent you build depends on. context length 131072 is the most the model can handle; Ollama does not use that much unless asked, because memory grows with the context, and the course asks for 8,192.

Step 4: Run One Prompt and Read What Is Loaded

Send the model one prompt from the terminal:

ollama run granite4.1:3b "In one sentence, what is a groundsheet for?"

The reply streams in word by word. This is the recorded reply; yours may be worded differently:

A groundsheets is a protective cover placed on the floor of a tent to prevent moisture, debris, and damage from the ground from entering the tent.

"A groundsheets" is a small grammar slip. Small local models make slips like this, and occasionally larger mistakes; the course checks answers rather than trusting them.

Straight afterwards, ask the server what it has loaded:

ollama ps
NAME             ID              SIZE      PROCESSOR    CONTEXT    RUNNER      UNTIL
granite4.1:3b    6fd349357287    2.5 GB    100% GPU     4096       llamacpp    4 minutes from now
ColumnMeaning in the recorded output
SIZEMemory in use: 2.5 GB, more than the 2.1 GB file, because the server also reserves memory for the context
PROCESSORWhere the model runs: 100% GPU here on an Apple M2. Without a usable GPU you will see 100% CPU; a split such as 40%/60% CPU/GPU means the model did not fit in GPU memory
CONTEXTThe context window of this load: 4,096 tokens, the default, because ollama run asked for nothing else. Course programs ask for 8,192, and ollama ps then shows 8192
RUNNERThe engine running the model: llamacpp
UNTILWhen the model will be unloaded. It stays in memory for five minutes after the last request, so the next request within that time starts at once; after that, the first request waits while the model loads again

Finally, ask the server for its version over HTTP, the way your programs will talk to it. On macOS and Linux:

curl http://127.0.0.1:11434/api/version

On Windows, curl in Windows PowerShell 5.1 is a name for a different command, so use either of these, which work in every version:

curl.exe http://127.0.0.1:11434/api/version
Invoke-RestMethod http://127.0.0.1:11434/api/version
{"version":"0.40.7"}

Each check proves something different, and none proves everything:

CheckProvesDoes not prove
/api/version answersA server is listening at that addressThat any model is present
ollama list shows the model and IDThe model's files are on this serverThat it can load or run
ollama ps shows it loadedIt loaded, and where it runsThat it can call tools from your code

The next lesson's readiness script closes the last gap by asking the model for a tool call from Python.

When the Result Differs

These are real outputs recorded on the author's computer, from a test server on a different port; on yours the port is normally 11434.

What you seeCauseFix
Error: could not connect to ollama server, run 'ollama serve' to start itNo server at the address: Ollama is not running, or OLLAMA_HOST points elsewhereStart the Ollama app (Linux: sudo systemctl start ollama); check OLLAMA_HOST is unset
curl: (7) Failed to connect to 127.0.0.1 port 11434The same, seen from curlAs above
Error: model 'granite4.1:3b' not found, or HTTP status 404 with {"error":"model 'granite4.1:3b' not found"}The server is running but this model is not on itollama pull granite4.1:3b; if you pulled it, check that the same server and model folder are in use
Error: listen tcp 127.0.0.1:11434: bind: address already in useYou ran ollama serve while a server, usually the app, was already runningDo not start a second server; use the running one
ollama: command not found (PowerShell: "is not recognized")The terminal predates the installation, or the macOS link was refusedOpen a new terminal; on macOS start Ollama again and accept the link
PROCESSOR shows 100% CPU on a computer with a GPUThe GPU is unsupported, or its driver is too oldCheck Ollama's hardware notes for your system; the course works on the CPU, only slower

Your Turn: Diagnose Three Outputs

A friend sends you three outputs from their setup. For each, name the cause, the evidence that shows it, and the fix:

  1. After restarting their laptop, ollama list prints Error: could not connect to ollama server, run 'ollama serve' to start it.
  2. They are sure Ollama is running, because ollama -v printed a version, but their request to http://127.0.0.1:11434/api/chat for granite4.1:3b returns status 404 with {"error":"model 'granite4.1:3b' not found"}.
  3. Following an old tutorial, they typed ollama serve and got Error: listen tcp 127.0.0.1:11434: bind: address already in use.

Success means each answer quotes the part of the output that gives the cause away and a fix that does not make things worse. Compare with the answers below.

Clean Up

There is nothing to remove: the course uses Ollama and the model in every lesson from now on. If you need the disk space back after the course, the final lesson explains how to remove the model (ollama rm granite4.1:3b), the practice folder and, if you wish, Ollama itself.

Check Your Understanding

  1. A classmate on a different kind of computer pulls the same model name and gets a different ID in ollama list. How can one name lead to different files, and why does it matter for a course?
  2. Which column of ollama ps tells you which engine runs the model, and which tells you whether it is using the GPU?

Answer and Reasoning

Your turn

  1. The server is not running. The evidence is "could not connect": the command reached no server at all. A restart stops the server unless the app starts at login. Start the Ollama app (Linux: sudo systemctl start ollama) and run ollama list again. If it still fails, check that OLLAMA_HOST is not set to another address.
  2. The server is running, but the model is not on it. ollama -v only shows that the command is installed (and, if the server answers, its version); the 404 body names the missing model. Run ollama pull granite4.1:3b, then ollama list to see its ID. If they had already pulled it, they may have pulled it into a different server, for example one started by hand with another OLLAMA_MODELS folder.
  3. A server is already running. "address already in use" means another program, almost certainly the Ollama app, already listens on 127.0.0.1:11434. Nothing needs fixing: close the second attempt and use the server that is running. Starting servers on other addresses to work around the error would leave two servers with different model folders.

Check your understanding

  1. A name such as granite4.1:3b is a label in the model library that points to a manifest, a list of files. The library can point the same label at a different build for a different platform, or at a newer build later. While the course was choosing its model, the same qwen3.5:4b name downloaded a different build on Apple silicon, run by a different engine, which ignored the context setting. For a course this matters because recorded outputs and timings come from one build; the ID lets you see whether you have the same one. Granite 4.1 3B used the same build and engine on every platform checked, one reason it was chosen.
  2. RUNNER names the engine (llamacpp in the recording). PROCESSOR shows where the model runs: 100% GPU, 100% CPU, or a split between them.

References

32 more lessons in the full course

Course access opens every lesson and adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 199 plus 18% GST. 90 days of online access. No auto-renewal.

Get the full course

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy