Aadhib
ENع

TUTORIAL

How to run an LLM locally: a practical guide for Mac, Windows and Linux

A step-by-step guide to running a large language model on your own computer with Ollama or LM Studio, choosing a model that fits your memory, exposing a local API, and fixing the failures people hit first. Every command comes from the tools' official documentation.

Running a language model on your own computer used to mean compiling things, hunting for model files and guessing at settings. It is now a short job on most recent machines. The hard part has moved: it is choosing a model your hardware can actually hold, and knowing what you have exposed once it is running.

Most guides stop at "install this, type that". They skip the memory arithmetic, they skip the fact that the default context window is small, and they rarely mention that the server you just started can be reached by other machines if you change one setting. This guide covers the whole path, on macOS, Windows and Linux, with two tools: Ollama and LM Studio. Every command below is taken from the tools' own documentation, which I read on the publish date and list at the end.

If you have not yet decided which model you want, read The best local LLMs for 2027 first. This article is about getting one running.

The short answer

  • Engineers, servers, scripts: install Ollama, run ollama run gemma4, and call it at http://localhost:11434.
  • Everyone else: install LM Studio, download a model from the Discover tab, chat in the Chat tab, and turn on the server in the Developer tab if you need an API.
  • Choosing a model: take the download size from the model page, and make sure your free memory (GPU memory, or unified memory on Apple Silicon) is comfortably larger than that.
  • Using it from code: both tools speak the OpenAI API. Point your client at http://localhost:11434/v1/ (Ollama) or http://localhost:1234/v1 (LM Studio's documented examples) and pass any string as the key.
  • Before sharing it on a network: both listen on 127.0.0.1 only by default. Keep it that way unless you add authentication or a proxy.
OllamaLM Studio
InterfaceCommand line and a menu bar or tray appDesktop app, plus the lms CLI
macOSSonoma (14) or newer; GPU on Apple M series, CPU only on IntelmacOS 14 or newer, Apple Silicon only
WindowsWindows 10 22H2 or newer; NVIDIA and AMD Radeon GPUsx64 with AVX2, or ARM (Snapdragon X Elite)
LinuxInstall script, systemd serviceAppImage; Ubuntu 20.04 or later
Local APIlocalhost:11434, native and OpenAI-compatibleOpenAI-compatible, examples on port 1234
Best forServers, automation, coding agentsTrying models, non-technical users

Step 1: check your hardware

A local model has to fit in memory, and it is fast only if it fits in fast memory. On a Mac with Apple Silicon that is unified memory, shared by the CPU and GPU. On a Windows or Linux PC it is the memory on your graphics card, with system RAM as a slower fallback.

What the tools ask for:

  • Ollama on macOS needs macOS Sonoma or newer. Apple M series Macs get GPU acceleration; Intel Macs run on the CPU only.
  • Ollama on Windows needs Windows 10 22H2 or newer, and NVIDIA driver 551.61 or newer if you have an NVIDIA card. Its hardware page lists NVIDIA GPUs from compute capability 5.0 upwards, including the RTX 30, 40 and 50 series and the GB10 in the DGX Spark.
  • LM Studio advises 16GB of RAM or more. It says 8GB Macs can run smaller models with modest context sizes, recommends at least 4GB of dedicated VRAM on Windows, and does not currently support Intel Macs.

In practice, 16GB is where local models start to be useful for real work, 32GB to 64GB is where they become good, and 128GB opens up the large mixture-of-experts models. I explain the bits-per-weight arithmetic behind that in the local LLM guide.

Step 2: install Ollama

Ollama's README gives one command per platform.

On macOS or Linux:

curl -fsSL https://ollama.com/install.sh | sh

On Windows, in PowerShell:

irm https://ollama.com/install.ps1 | iex

There are also ordinary installers (a .dmg for Mac and OllamaSetup.exe for Windows) on the download page. The Windows installer does not need administrator rights and installs into your home folder. Once installed, Ollama runs in the background and the ollama command works in any terminal.

On Linux, the documentation recommends running Ollama as a systemd service so it starts on boot. If you used the install script that is set up for you; check it with:

sudo systemctl status ollama

If you have an NVIDIA card on Linux, install the CUDA drivers and confirm nvidia-smi prints your GPU. AMD cards use ROCm, with Vulkan as a fallback.

Step 3: run your first model

ollama run gemma4

The first run downloads the model, then drops you into a chat. The other commands you will use daily:

ollama pull qwen3.5:9b   # download without running
ollama ls                # list downloaded models
ollama ps                # show what is loaded, and where
ollama stop gemma4       # unload a model from memory
ollama rm gemma4         # delete it from disk

Model names have tags for size. The Ollama library page lists them with their download sizes, and that is the number to compare with your memory. On the publish date the pages showed, for example:

TagDownload sizeContext
gemma4:e4b (the default gemma4)6.6GB to 9.5GB128K
gemma4:12b7.7GB to 8.0GB256K
qwen3.5:9b6.6GB to 7.6GB256K
gemma4:26b16GB to 19GB256K
qwen3.5:27b17GB to 20GB256K
gemma4:31b19GB to 20GB256K

A range means several quantisations are offered under that size. My rule of thumb: if the download is more than about two thirds of your free fast memory, pick the next size down. On a 16GB laptop that means the 9B and 12B class. On a 32GB machine the 26B to 31B class fits. On Apple Silicon, the library also lists -mlx tags, built for Apple's MLX framework.

One thing to know before you go further. Ollama now offers cloud models as well as local ones, and some tags (such as gemma4:cloud) run on Ollama's servers rather than your machine. If the reason you are doing this is to keep data on your own hardware, stick to local tags. The FAQ also documents a local-only mode: set OLLAMA_NO_CLOUD=1, or put "disable_ollama_cloud": true in ~/.ollama/server.json.

Or use LM Studio instead

LM Studio is the better choice if you, or the person you are setting this up for, would rather not use a terminal.

  1. Download and install LM Studio from its website.
  2. Open the Discover tab and choose a model, either from the curated list or by searching for a name.
  3. Open the Chat tab, load the model with the model loader, and start chatting. Load settings, such as how much to put on the GPU and the context length, are in the same place.

LM Studio's documentation says it can run entirely offline once you have the model files, and that nothing you type into a chat with a local model leaves your device. Search, model downloads and app updates need the internet; chatting does not.

It also ships a command line tool, lms, which works after you have opened the app once:

lms get              # search and download models
lms load <model>     # load a model into memory
lms ps               # show loaded models
lms server start     # start the API server

For a machine with no screen, LM Studio documents a headless daemon called llmster:

curl -fsSL https://lmstudio.ai/install.sh | bash   # macOS or Linux
lms daemon up

Step 4: call it from your own code

This is the step that turns a chat toy into something useful. Both tools expose a local HTTP API, and both offer OpenAI-compatible endpoints, so most code written for a hosted model works after changing two lines.

Ollama, using its native API:

curl http://localhost:11434/api/chat -d '{
  "model": "gemma4",
  "messages": [{"role": "user", "content": "Summarise this in one line: ..."}],
  "stream": false
}'

Ollama or LM Studio, using the OpenAI Python client:

from openai import OpenAI
 
client = OpenAI(
    base_url="http://localhost:11434/v1/",  # LM Studio: http://localhost:1234/v1
    api_key="ollama",  # required by the client, ignored by the server
)
reply = client.chat.completions.create(
    model="gemma4",
    messages=[{"role": "user", "content": "Hello"}],
)
print(reply.choices[0].message.content)

LM Studio's documentation uses port 1234 in its examples. Its CLI reference says that if you start the server without --port, it reuses the last port you used, so check which port your server is on if a request fails.

The same local API is what lets other tools use your model. Ollama's ollama launch command connects coding agents such as Claude Code, Codex and OpenCode to it. Automation tools can call it too: I covered n8n's Ollama node in n8n vs Zapier vs Make, and the coding side in the best AI coding tools for 2027. Be realistic, though. A small local model is fine for summarising, extracting and drafting. It is much weaker than a frontier model on long agentic coding tasks.

Step 5: let other machines use it, carefully

By default, Ollama binds to 127.0.0.1 on port 11434, so only the machine it runs on can reach it. To serve a team, you change the bind address with the OLLAMA_HOST environment variable. On Linux, with the systemd service, run sudo systemctl edit ollama.service and add this under [Service]:

Environment="OLLAMA_HOST=0.0.0.0:11434"

Then reload and restart:

sudo systemctl daemon-reload
sudo systemctl restart ollama

On a Mac running the app, the FAQ uses launchctl setenv OLLAMA_HOST "0.0.0.0:11434" and a restart. On Windows, you set it as a user environment variable and restart Ollama from the Start menu.

In LM Studio it is the "Serve on Local Network" option, or lms server start --bind 0.0.0.0. LM Studio's own page warns that any bind other than 127.0.0.1 exposes the server beyond localhost, and recommends turning on authentication.

That warning deserves weight. A model server on 0.0.0.0 with no authentication answers anyone who can reach that port. For anything beyond your own desk, put it behind a reverse proxy that handles authentication and TLS (Ollama's FAQ shows an Nginx example), and restrict the port with a firewall. Running the model locally keeps prompts away from a model provider. It does not, by itself, make the deployment compliant with PDPL or any other law; access control, logging and retention still decide that.

The failures people hit first

It is painfully slow. Run ollama ps and look at the Processor column. 100% GPU is what you want. 100% CPU, or a split such as 48%/52% CPU/GPU, means the model did not fit in GPU memory and part of it is running from system RAM. Use a smaller model or a smaller quantisation. On Linux, Ollama's hardware page also notes that after suspend and resume the NVIDIA GPU is sometimes not detected, and gives the fix.

It forgets the start of a long document. Ollama's FAQ says its default context window is 4,096 tokens, whatever the model supports. Raise it with OLLAMA_CONTEXT_LENGTH when starting the server, with /set parameter num_ctx in a chat, or with num_ctx in an API request. More context costs more memory, so raise it to what you need, not to the maximum.

The first answer takes ages, then it is fine. That is the model loading into memory. Ollama keeps a model loaded for five minutes by default. The OLLAMA_KEEP_ALIVE variable or the keep_alive API parameter changes that, and -1 keeps it loaded indefinitely.

The disk filled up. Models are large. Ollama stores them in ~/.ollama by default, and OLLAMA_MODELS moves them to another drive. ollama rm deletes ones you no longer use.

Requests start failing under load. Ollama queues requests and returns a 503 when the queue is full. The FAQ documents OLLAMA_NUM_PARALLEL, OLLAMA_MAX_LOADED_MODELS and OLLAMA_MAX_QUEUE for tuning this, and each parallel request needs more memory. If several people depend on one model all day, that is the point to look at a serving engine built for concurrency.

Where llama.cpp fits

Ollama is built on llama.cpp, and LM Studio uses it too. You can also run llama.cpp directly. Its README now has a one-line installer (curl -LsSf https://llama.app/install.sh | sh, or the PowerShell equivalent) and two commands: llama cli -hf <repo> to chat with a model from Hugging Face, and llama serve -hf <repo> to start an OpenAI-compatible server. It is the most direct route, with the most settings exposed, and the right choice when you want to control exactly which quantisation and options you run.

What I would do

For one engineer on a laptop: Ollama, a 9B to 12B model, and the OpenAI-compatible endpoint wired into whatever you are building. For a colleague who wants to try local AI without a terminal: LM Studio. For a small team sharing a machine: Ollama as a service on a box with 64GB to 128GB of memory, bound to the internal network only behind a proxy with authentication. That is the shape of the setup I use for internal agents on a Mac Studio, and I wrote about the smaller version of it in Why I'm interested in Mac minis for local AI deployments.

What I would not do is buy hardware first. Run the model you have in mind on a machine you already own, at the quantisation you would use, on your real documents. Then size the hardware. And keep the hosted models in the picture: for many companies the answer is a mix, which I cover in The best architecture is sometimes hybrid.

If you want a local model running inside your own network, sized and secured properly, that is what my local AI deployment work covers.

Sources

  1. 01Ollama READMEOllama
  2. 02Ollama on macOSOllama
  3. 03Ollama on WindowsOllama
  4. 04Ollama on LinuxOllama
  5. 05Ollama local FAQOllama
  6. 06Ollama OpenAI compatibilityOllama
  7. 07Ollama hardware supportOllama
  8. 08Ollama cloudOllama
  9. 09gemma4 in the Ollama libraryOllama
  10. 10qwen3.5 in the Ollama libraryOllama
  11. 11LM Studio system requirementsLM Studio
  12. 12LM Studio offline operationLM Studio
  13. 13LM Studio OpenAI compatibility endpointsLM Studio
  14. 14LM Studio serve on local networkLM Studio
  15. 15LM Studio headless modeLM Studio
  16. 16lms server startLM Studio
  17. 17llama.cpp READMEggml-org

If this was useful, follow what I’m building.

All notes →

Projects and case studies

All notes