Local LLM Deployment: A Step-by-Step Guide from Environment Setup to First Inference

    A practical guide to deploying large language models locally. Learn how to assess hardware requirements, install the Ollama runtime, pull a model, run your first inference, call the model via API, and troubleshoot common issues—all with verification steps at every stage.

    1. Who This Guide Is For

    Deploying a large language model locally means downloading the model weights to your own computer or server and running inference on your own hardware. Compared with calling a cloud service, local deployment offers three main advantages. First, your input text and generated results never leave your machine, which makes it suitable for sensitive content such as contracts, medical records, and internal documents. Second, it works even without an internet connection. Third, it makes it easy to iterate on prompts, do secondary development, and compare the performance of different models. The trade-off is that you bear the hardware cost and maintain the runtime environment yourself.

    This guide targets two audiences. The first is developers who are new to large language models and want to get their first conversation running within an hour. The second is technical leads evaluating local inference options for their teams, who need to understand resource requirements and common risks.

    The guide is organized into five steps: assessing hardware and disk space, installing and verifying the inference runtime, pulling a model and completing your first inference, calling the model through an API, and finally troubleshooting issues and reviewing security settings. Each step includes a verification method, so if something goes wrong you can pinpoint the exact stage.

    2. Assessing Resources Before Deployment

    Large model inference places heavy demands on memory and GPU memory (VRAM). Before deploying, estimate the size of the model weights with this formula:

    Weight size ≈ parameter count × bytes per parameter

    Take a 7-billion-parameter (7B) model as an example. Without quantization, each parameter typically takes 2 bytes (FP16 precision), so the weights are about 14 GB. With 4-bit quantization, each parameter takes roughly 0.5 bytes, making the theoretical weight size about 3.5 GB. In practice, downloaded 4-bit quantized files are usually larger, because some layers retain higher precision and the quantization format adds extra metadata. When choosing a model, use the actual download size as your reference. You also need to reserve headroom for the context cache (KV Cache) and system overhead—the longer the context, the more memory is consumed.

    The table below shows reference configurations for common model sizes under 4-bit quantization. The numbers are estimates; use the sizes shown by ollama list as the actual values:

    Parameter size Download size (approx.) Recommended VRAM (GPU inference) Recommended RAM (CPU inference or when VRAM is insufficient)
    1.5B 1 GB 4 GB 8 GB
    7B 4.7 GB 8 GB 16 GB
    14B 9 GB 12 GB or more 32 GB

    Keep three points in mind when choosing a model size. First, VRAM determines inference speed. A model that fits entirely in VRAM runs fastest; if part of it spills over into system memory, speed drops noticeably. Second, without a dedicated GPU, the model can only run on the CPU. Small models are barely usable, but large models generate text very slowly—suitable for testing only. Third, Macs with Apple silicon use unified memory, and the memory available to the model is a portion of the machine’s total memory, so plan based on unified memory capacity.

    As for disk space, the runtime, model files, and temporary download files together require several gigabytes. Aim for at least twice the model file size in free space. For example, if you plan to pull a 4.7 GB model, your system disk should have at least about 10 GB free. Interrupted downloads leave temporary files behind—clean them up once you confirm they are no longer needed. Where possible, install into a directory without spaces or non-ASCII characters to avoid compatibility issues with some tools.

    Resource checklist:

    • Confirm your GPU model and VRAM size (on Windows, check the “Performance” tab in Task Manager; for NVIDIA GPUs, run nvidia-smi).
    • Confirm total system memory.
    • Confirm that free space on the target disk is at least twice the model size.
    • Confirm your network can reach the model registry—the first download moves several gigabytes of data.

    3. Installing the Local Inference Runtime

    A local inference runtime is software that loads the model, performs inference, and provides interfaces for interaction. The runtime and the model are two independent components: the runtime provides the computing environment, while the model provides the parameters and capabilities. They are installed and managed separately—swapping models does not require reinstalling the runtime.

    This guide uses Ollama as the runtime. It supports Windows, macOS, and Linux, offers a command-line tool, and starts an HTTP service on your machine for other programs to call. Download the installer from the official website, ollama.com. Do not download it from unverified third-party sites.

    3.1 Installing by Operating System

    Windows: Go to the official download page, download the Windows installer, and double-click it to complete the installation following the prompts. Once installed, Ollama runs in the background as a service.

    macOS: Download the .dmg package from the official website and drag the app into the “Applications” folder, then launch it. If you have Homebrew installed, you can also run:

    1. brew install ollama

    Linux: The official website provides a one-line installation script. Before running it, download the script and inspect its contents:

    1. curl -fsSL https://ollama.com/install.sh -o install.sh
    2. less install.sh
    3. sh install.sh

    The installation script usually requires administrator privileges to write to system directories. Unless you have verified the script’s contents, do not pipe a remote script directly into sh.

    3.2 Verifying the Installation

    After installation, open a terminal (on Windows, use PowerShell or Command Prompt) and run:

    1. ollama --version

    Expected output is similar to ollama version is 0.x.x, with the actual version depending on what you installed. If you get a “command not found” error, close and reopen the terminal so the new environment variables take effect; if it still fails, check whether the installation path has been added to PATH.

    Then check that the background service is responding:

    1. curl http://localhost:11434/api/version

    If it returns JSON containing a version number, the service is running. Windows users without curl can open http://localhost:11434 in a browser—the message “Ollama is running” indicates the service is working.

    If the service has not started, Linux and macOS users can run ollama serve manually. This command runs the service in the foreground, and it stops when you close the terminal.

    4. Pulling a Model and Running Your First Inference

    With the runtime installed, you still need to pull a model. Model names follow the format “model:parameter-size”. The following command pulls a 7B Qwen model:

    1. ollama pull qwen2.5:7b

    A progress bar displays during the download. The files are large, and the time required depends on your network speed. Once the download completes, list your local models:

    1. ollama list

    The output lists model names, IDs, sizes, and modification times. Note the size and compare it against your earlier resource assessment.

    Now run your first inference. The simplest way is to enter interactive mode:

    1. ollama run qwen2.5:7b

    At the prompt, type a question—for example, “Explain what quantization is in three sentences”—and the model will generate the answer token by token. Type /bye to exit the conversation.

    Running ollama ps in another terminal shows which models are loaded. The PROCESSOR column indicates whether the model is running on the GPU, CPU, or a mix of both. If it shows pure CPU, the GPU was not detected or VRAM is insufficient, and speed will be noticeably slower.

    Once your first inference succeeds, the core local deployment pipeline is working.

    5. Calling the Model via API

    The command line is fine for manual testing, but to integrate the model into your own programs you need to call the HTTP API. Ollama serves an API at http://localhost:11434 by default, with two commonly used endpoints.

    The first is the generation endpoint /api/generate, suitable for single-turn text generation. The following command sends a request and disables streaming so the result is returned in one piece:

    1. curl http://localhost:11434/api/generate -d '{
    2. "model": "qwen2.5:7b",
    3. "prompt": "Explain local deployment in one sentence.",
    4. "stream": false
    5. }'

    In the returned JSON, the response field contains the generated text.

    The second is the chat endpoint /api/chat, suitable for multi-turn conversations, where conversation history is passed via the messages array:

    1. curl http://localhost:11434/api/chat -d '{
    2. "model": "qwen2.5:7b",
    3. "messages": [
    4. {"role": "system", "content": "You are a concise technical assistant."},
    5. {"role": "user", "content": "What is the KV Cache?"}
    6. ],
    7. "stream": false
    8. }'

    Here is a Python example. Run pip install requests first:

    1. import requests
    2. resp = requests.post(
    3. "http://localhost:11434/api/chat",
    4. json={
    5. "model": "qwen2.5:7b",
    6. "messages": [{"role": "user", "content": "List three advantages of local deployment."}],
    7. "stream": False,
    8. },
    9. timeout=120,
    10. )
    11. resp.raise_for_status()
    12. print(resp.json()["message"]["content"])

    If you already have code written against the OpenAI API, Ollama also provides a compatible endpoint at http://localhost:11434/v1/. Simply point the request URL to that endpoint and change the model name to your local model name—usually no other code changes are needed. The API key field can be filled with any non-empty string, since the local service does not validate keys by default.

    Two things to note when calling the API. First, the initial request loads the model into memory, which takes longer, so set a generous timeout—the example uses 120 seconds. Second, for long-form generation, set stream to true to receive the output incrementally, which gives users a better waiting experience.

    6. Troubleshooting Common Issues

    The following issues are the most common during a first deployment. Match the symptom to the fix below.

    1. “Could not connect to ollama server” or the API does not respond. The background service is usually not running. On Linux and macOS, run ollama serve; on Windows, check whether Ollama is running in the system tray, then verify again with curl http://localhost:11434/api/version.

    2. Port conflict preventing the service from starting. Check whether port 11434 is already in use by another program. To change the port, set the environment variable OLLAMA_HOST, for example 127.0.0.1:11435, restart the service, and update the endpoint in your calling code accordingly.

    3. Out-of-memory error when loading a model, or the process exits immediately. The model exceeds your available VRAM and memory. Switch to a smaller parameter size, for example from 14B to 7B, or close other memory-hungry programs and retry.

    4. Extremely slow generation. Check the PROCESSOR column in ollama ps. If CPU usage is high, part or all of the model was not loaded into VRAM. Verify that your GPU drivers are installed correctly and VRAM is sufficient, or choose a smaller model.

    5. Download interrupted or abnormally slow. Simply run ollama pull again to resume—already-downloaded portions are kept. If progress stalls for a long time, check your proxy settings or network connection.

    6. Insufficient disk space. Models are stored by default in .ollama/models under your user directory—on Windows, C:\Users\<username>\.ollama\models. If your system drive is running low, set the environment variable OLLAMA_MODELS to a directory on another drive and restart the service. Remove unneeded models with ollama rm model:parameter-size.

    7. Output noticeably deviates from expectations. Smaller models have limited capability, and output is affected by prompts and parameters. Try a larger model for comparison and refine your prompts before concluding that the deployment itself is broken.

    7. Security and Compliance Notes

    Local deployment keeps your data on your machine, but it is not risk-free. Confirm the following during deployment.

    First, keep the service listening on the local address only. Ollama accepts connections only from the local machine by default. Do not casually set OLLAMA_HOST to 0.0.0.0 to make it accessible on your LAN, because the service itself has no authentication. If you genuinely need remote access, put it behind an authenticating reverse proxy and configure a firewall to allow only trusted addresses.

    Second, obtain the runtime and models from official sources. Installers and models should come from the official website or official model library. Check the publisher information before installing, and after downloading you can review model summaries with ollama list to confirm they match the expected model.

    Third, comply with the model license. License terms vary widely between models—some restrict commercial use, others require attribution or limit usage scope. Read the license text for each model before team-wide use.

    Fourth, run with minimal privileges. Day-to-day use does not require running the inference service as an administrator. Only installation and system path changes need elevated permissions.

    Fifth, do not treat the local service as a security boundary. Model output may contain errors and should never be directly used to execute system commands or write to production databases. Always review generated code and commands manually before running them.

    8. Post-Deployment Checklist

    Once the following checks pass, your local deployment is ready for use:

    • ollama --version outputs a version number.
    • curl http://localhost:11434/api/version returns version information.
    • ollama list shows the models you pulled.
    • ollama run completes at least one full conversation turn.
    • /api/generate or /api/chat returns a non-empty result.
    • ollama ps shows the model running on the expected processor.
    • The service listens only on the local address, and the model license has been confirmed.

    By following these steps, you can independently go from environment preparation to API integration. After deployment, you can choose between model sizes such as 1.5B, 7B, and 14B based on your tasks and hardware, balancing speed, quality, and resource usage.