Sub topic 3
Installing Ollama and checking that the server is running
This chapter covers installing Ollama on macOS, Linux, Windows, or Docker, and confirming that its background server works. It assumes you are comfortable in a terminal and know basic HTTP and JSON. It also assumes that you have read the previous chapter on how Ollama is structured: a CLI, a local server, and a model store.
What the installer sets up
Installing Ollama gives you two things:
- The
ollamacommand-line program. - A server process that listens on your machine and does the actual work of loading and running models.
The CLI is a client of that server. When you type ollama run, the CLI sends HTTP requests to the server. If the server is not running, most commands fail with a connection error.
The server listens on 127.0.0.1 (localhost), port 11434. Only programs on your own machine can reach it by default. Chapter 16 covers changing that.
Installing on each platform
Pick the section that matches your system.
macOS
Download the app from the Ollama website, unzip it, and move it to Applications. Opening it starts the server and adds a menu bar icon. If you use Homebrew, you can install the command-line formula instead:
brew install ollama
brew services start ollamaThe Homebrew route has no menu bar app, so brew services is what keeps the server running.
Linux
The official install script downloads the binary and, on systems with systemd, registers a service named ollama:
curl -fsSL https://ollama.com/install.sh | shThe script also detects NVIDIA or AMD GPUs and installs the pieces it needs. If your distribution does not use systemd, such as inside some containers, the service is not created. You then start the server yourself (see below).
Windows
Download OllamaSetup.exe from the website and run it. It installs per user and does not need administrator rights. Afterward, Ollama starts in the background and shows an icon in the system tray. Open a new PowerShell or Command Prompt window so the updated PATH is picked up.
Docker
You can run the server in a container. This is useful for servers and for keeping the install separate from your system:
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
docker exec -it ollama ollama run llama3.2The named volume ollama keeps downloaded models when you recreate the container. Without it, you would download the models again each time. GPU access needs extra setup, such as the NVIDIA Container Toolkit and the --gpus=all flag. It is not covered here.
Checking the install
Start with the CLI, then check the server.
Step 1: Is the CLI installed?
ollama --versionThis prints the version. If the server is not reachable, it may also print a warning that it could not connect to a running Ollama instance. That warning tells you the CLI is installed but the server is not running.
Step 2: Is the server answering?
curl http://localhost:11434/A healthy server replies with the plain text Ollama is running. You can also ask for structured data:
curl http://localhost:11434/api/version
curl http://localhost:11434/api/tags/api/version returns a small JSON object such as {"version":"0.5.7"}. Your version number will differ. /api/tags lists the models stored locally. On a new install, the list is empty: {"models":[]}.
An empty list is a good sign. It means the server is up and can read its model store. You have not pulled any models yet.
Step 3: Check from a script
The same check works in Python. This is handy for startup checks in your own programs:
import requests
try:
resp = requests.get("http://localhost:11434/api/version", timeout=5)
resp.raise_for_status()
print("Ollama is up, version", resp.json()["version"])
except requests.exceptions.ConnectionError:
print("Cannot connect: the Ollama server is not running on port 11434.")
except requests.exceptions.RequestException as err:
print("Server answered, but with an error:", err)The code separates two failures. A ConnectionError means nothing is listening on the port. Other errors mean something answered with a bad status, which points to a different problem.
Starting and stopping the server
How the server starts depends on how you installed it.
| Install method | How the server runs | How to check or restart |
|---|---|---|
| macOS app | Menu bar app starts it at login | Reopen the app from Applications |
| Homebrew | Background service | `brew services restart ollama` |
| Linux script | systemd service `ollama` | `systemctl status ollama`, `sudo systemctl restart ollama` |
| Windows installer | Tray app starts it at login | Reopen Ollama from the Start menu |
| Docker | Container process | `docker ps`, `docker restart ollama` |
On Linux, you can read the server's logs with:
journalctl -u ollama --no-pager | tail -n 50If you have no service manager, or you want to watch the server's output directly, run it in the foreground:
ollama serveThis occupies the terminal. Leave it running and open a second terminal for your other commands. Stop it with Ctrl+C.
Where models are stored
Downloaded models can take many gigabytes, so it helps to know where they go.
| System | Default model directory |
|---|---|
| macOS | `~/.ollama/models` |
| Linux (systemd service) | `/usr/share/ollama/.ollama/models` |
| Windows | `C:\Users\<username>\.ollama\models` |
| Docker image | `/root/.ollama` inside the container |
On Linux, the service runs as its own ollama user. That is why models do not appear in your home directory. If your root disk is small, you can move this directory with an environment variable. Chapter 16 shows how.
Common installation problems
command not found: ollama. The binary is not on yourPATH. On Windows, open a new terminal. On Linux, check that/usr/local/bin/ollamaexists.- Connection refused on port 11434. The server is not running. Start it using the table above, then repeat the
curlcheck. - Another program uses the port.
ollama servefails withaddress already in use. Either a second Ollama is running, or another program holds the port. On Linux or macOS,lsof -i :11434shows which process it is. - Works in the terminal, fails in a container or WSL.
localhostinside a container is the container itself. Publish the port with-p 11434:11434. If the client is in another container, use a hostname that reaches the server. - The version check works, but models run slowly. The install is fine. The server may have fallen back to the CPU because it did not find your GPU. Chapter 17 covers diagnosing that.
What you have now
After this chapter you should have the CLI on your PATH, a server answering on port 11434, and an empty model list. The next chapter pulls a model and starts a chat.
Exercise
You run ollama --version and see a warning that it could not connect to a running Ollama instance. Then you run ollama serve in a second terminal and get "address already in use". What does this combination tell you, and what should you check next?
Show answer
The CLI is installed. The "address already in use" error means something already holds port 11434, so a server is probably running already, possibly a different instance such as a service or container. The earlier connection warning may be explained by a different host or port setting, or by a server that was still starting. Run curl http://localhost:11434/ to see whether it answers "Ollama is running". If it does not, find the process using the port (for example with lsof -i :11434) and check whether it is Ollama or another program.