How to Deploy Open-Source Large Language Models Locally: A Practical Guide
This article explains how to run open-source large language models on a local machine. It covers hardware evaluation, quantization choices, model-size selection, installing a local inference runtime, configuring listening addresses and firewall rules, downloading and running quantized models, verifying basic behavior, and troubleshooting common deployment issues.
1. Why Deploy Open-Source LLMs Locally?
As large language models become more capable, using cloud APIs has become common. However, deploying an open-source large language model on your own computer is still a practical requirement for many users. Local deployment is often motivated by the following needs:
- Data stays on the local machine: When working with internal code, contract drafts, customer information, or other sensitive content, local inference can reduce the risk of sending data outside from the source. This is especially useful for teams with strict compliance requirements.
- Offline availability and predictable latency: Local models remain usable when the network is unavailable, when traveling, or inside isolated networks. Response time is also less affected by cloud queues and network jitter.
- Different cost structure: Local deployment is mainly a one-time hardware investment. If used frequently, the marginal cost approaches zero.
- High controllability: Quantization precision, context length, inference parameters, and runtime behavior can be adjusted freely. A local model can also be integrated into your own toolchain and business workflows.
It is also important to be realistic. Because of the hardware limits of a personal computer, lightweight local models generally perform worse than large cloud-hosted models on complex reasoning, long-context understanding, and multi-turn tasks. It is usually best to start with a smaller quantized model, complete the workflow, and then upgrade according to your hardware.
2. Before Deployment: Hardware, Quantization, and Expectations
2.1 Evaluate the hardware
Whether local deployment runs smoothly depends mainly on memory, GPU memory, and disk space:
| Component | Minimum | Recommended | Notes |
|---|---|---|---|
| RAM | 8 GB | 16 GB or more | Must hold model weights, context cache, and runtime overhead. Less RAM limits the size of models you can use. |
| GPU | Can run without a dedicated GPU using CPU inference | A mid-range dedicated GPU with 6–12 GB VRAM, or a unified-memory chip platform | A dedicated GPU can significantly accelerate inference. Windows/Linux systems need the corresponding vendor compute stack; unified-memory platforms usually have simpler driver requirements. |
| Disk | About 5 GB free | 20 GB or more | Each quantization is stored separately, so leave some extra space. |
| Network | Access to the model repository | Stable high-speed network | The first download transfers the full model files. |
A dedicated GPU is not strictly required. CPU inference is slower, but the workflow can still be completed. On platforms with a unified memory architecture, the CPU and GPU share the same physical memory. For example, on a 16 GB machine, quantized models below the 10-billion-parameter range usually run smoothly.
2.2 Understand quantization: the key to smaller models
Open-source models are usually released in different precision formats. Take a 70-billion-parameter model as an example. In FP16, each parameter takes about 2 bytes, so the weights alone need about 140 GB. A personal computer cannot easily handle this. Quantization compresses weights into lower bit widths, such as 4-bit, reducing both model size and memory usage to about one-quarter of the original, while usually keeping precision loss limited. Common trade-offs are:
- Aggressive quantization (2–3 bits): Very small model size and fast inference, but noticeably lower answer quality and stability.
- Balanced quantization (4–5 bits): A good compromise between size and quality, and the mainstream choice for personal computers.
- High-fidelity quantization (8 bits or higher): Closer to original precision, but requires more memory.
Quantization schemes also differ. For example, some preserve higher precision for critical layers, while others use weight-group scaling. These choices affect output quality even at the same bit width. It is a good idea to compare several versions and run a few tests before choosing one.
2.3 Choose an appropriate model size
- 2-billion-parameter class (2B): After 4-bit quantization, it usually takes about 2 GB. It can run on an 8 GB machine and is suitable for learning, validation, and simple tasks.
- 7-billion-parameter class (7B): After 4-bit quantization, it usually takes about 5 GB. This is a cost-effective tier for local deployment and is generally sufficient for everyday Q&A and text processing.
- 14-billion-parameter class (14B) and above: After 4-bit quantization, it usually needs about 10 GB of memory. Performance is clearly limited by hardware, so it benefits more from dedicated GPU acceleration.
Within the same parameter range, different models have different focuses. Some are optimized for code generation, some for multilingual understanding, and some for instruction following. If you plan to build a coding assistant later, prioritize models that perform better on code-related tasks.
3. Step 1: Install a local inference runtime
3.1 What is a local inference runtime?
A local inference runtime is an open-source tool whose core job is to load and run large models. It usually provides:
- Downloading, caching, and managing model files from a model repository;
- Automatic scheduling of CPU, GPU, and other compute resources, and loading models accordingly;
- Direct interaction through a command-line chat interface, or an HTTP interface accessible on the local machine;
- Optimized quantization formats that provide better inference speed on personal computers.
These tools support mainstream model families and multiple quantization formats. They provide installers for Windows, macOS, and Linux, and the installation and onboarding thresholds are relatively low.
3.2 Install the inference runtime
- Download the installer: Visit the project’s official website and choose the installer for your operating system. On Linux, you can also use the official installation script.
- Complete the installation:
- Windows and macOS: Double-click the installer and follow the wizard.
- Linux: The official installation script downloads the program, registers a system service, and enables startup at boot.
- Verify the installation:
# Display the version number; if it prints successfully, the installation is completeollama --version
3.3 Configure the listening address and port on Linux
On Linux, the installation script usually runs the inference runtime as a systemd service. By default, it listens only on 127.0.0.1:11434. Here, 127.0.0.1 is the local loopback address, meaning only programs on the same machine can access it. The example below shows how to configure it to listen on port 11434.
Option 1: Edit the service file directly
If the service is registered at a path such as /etc/systemd/system/ollama.service, you can edit that file and add the listening address configuration under the [Service] section:
[Service]# Local-only access: 127.0.0.1:11434# LAN access: 0.0.0.0:11434 (listen on all network interfaces)Environment="OLLAMA_HOST=0.0.0.0:11434"
Option 2: Create a systemd drop-in override file (recommended)
Editing the original service file directly may be overwritten by a system update. A safer approach is to create a drop-in override file that declares only the changes you need while preserving the original configuration:
# 1. Create the override configuration directorysudo mkdir -p /etc/systemd/system/ollama.service.d# 2. Write the override configuration (adjust the port if needed)sudo tee /etc/systemd/system/ollama.service.d/override.conf > /dev/null <<EOF[Service]Environment="OLLAMA_HOST=0.0.0.0:11434"EOF# 3. Reload systemd configuration and restart the servicesudo systemctl daemon-reloadsudo systemctl restart ollama.service# 4. Confirm that the service status is active (running)sudo systemctl status ollama.service
Notes:
Environmentsets environment variables for the service process.OLLAMA_HOSTdetermines the address and port on which the inference runtime listens.daemon-reloadtells systemd to reread the modified configuration files, andrestartapplies the new configuration.- If the service name in the commands differs from the actual name on your machine, use the actual name. You can find it with
systemctl list-unit-files | grep ollama.
3.4 How to choose the listening address: security first
When changing the listening address, choose carefully based on the intended access scope:
127.0.0.1:11434: Local-only access. This is the safest option and is suitable for single-machine use.0.0.0.0:11434: Listens on all network interfaces. Other devices on the LAN can access it, but the firewall port must be opened accordingly. Do not expose it directly to the public internet.192.168.x.x:11434: Listens only on a specific internal network interface IP. This allows access only from that network segment and is more precise than0.0.0.0.
The commands for opening a firewall port vary by distribution and firewall tool. Here are two common examples:
# For systems using firewalldsudo firewall-cmd --permanent --add-port=11434/tcpsudo firewall-cmd --reload# For systems using ufwsudo ufw allow 11434/tcp
In addition, many Linux distributions enable mandatory access control mechanisms such as SELinux by default. Even if the firewall allows the port, a service running in a restricted mode may still block external access. During troubleshooting, use sestatus to check the status and adjust the relevant policies if necessary.
If you truly need external access, such as from a cloud server, avoid opening the inference service port directly. Instead, place a reverse proxy with authentication and encrypted transmission in front of it. Expose only the proxy port, and keep the inference service itself bound to the loopback address.
3.5 Notes for other operating systems
- Windows: After a default installation, the inference runtime usually runs as a background application with a system tray icon and listens on
127.0.0.1:11434. To change this, set variables such asOLLAMA_HOSTunder System Properties → Advanced → Environment Variables, then restart the application. If other devices on the LAN need access, also allow the program through Windows Defender Firewall on private networks. - macOS: It usually runs as a menu bar application and can also be started manually from the terminal. For cross-device access, confirm that incoming connections are allowed under System Settings → Network → Firewall.
4. Step 2: Download and run a quantized model
4.1 Download and start with one command
After installing and configuring the inference runtime, run the following command in a terminal:
ollama run gemma4:e2b
gemma4:e2b is a combination of model name and version tag:
- The part before the colon is the model identifier, which determines the model’s capabilities and parameter size.
- The part after the colon is the tag, usually corresponding to different quantization schemes. Letters indicate bit width, and the suffix indicates a specific quantization strategy. For example, Q4-series tags commonly include
q4_0andq4_K_M.
A model often provides multiple tags, from aggressive quantization to near-original precision. When hardware is limited, Q4-series tags are usually a good starting point. This command automatically performs the following steps:
- It checks the local cache directory, such as
~/.ollama/models, for an existing model. - If the model does not exist, it downloads the corresponding model files from the model repository.
- After downloading, it loads the model into memory and VRAM.
- It enters an interactive chat interface. You can type a message and press Enter to send it.
For example, using the e2b tag with about 7 billion parameters and 4-bit quantization, the downloaded model takes about 7.2 GB of disk space. The actual size may vary, so make sure you have at least twice the model size available before downloading.
On slower or restricted networks, the first download may be slow. Depending on your region and network conditions, you may need to use a download tool, a mirror source, or manually download and import the model files into the local runtime. Refer to the official documentation for the current download source and procedure.
4.2 Interactive mode and service mode
The command above enters interactive chat mode, which is suitable for quick testing. If you want other programs to call the model, start the service in the background:
ollama serve
Once started, the service provides a local HTTP interface through port 11434, or the port specified by OLLAMA_HOST. On Linux, you can also manage the service with systemctl:
sudo systemctl enable --now ollama.service
This makes the service start at boot and run continuously in the background.
4.3 Verify that the model works
After the model is running, run the following tests in order:
- Identity awareness: Ask questions such as “Who are you?” or “What model are you?” Lightweight quantized models usually give approximate answers, such as a general model name or “a language model.” Do not expect perfect precision.
- Chinese ability: Ask an open-ended question in Chinese, for example, asking the model to introduce West Lake in Hangzhou in three sentences. Check whether the answer is fluent and natural, and whether there are obvious language-mixing or grammar issues.
- Simple reasoning: Ask, “Xiaoming has 23 yuan. He buys two notebooks that cost 6 yuan each. How much money does he have left?” Check whether multi-step calculation and logic are correct.
- Code ability (optional): Ask the model to write a simple function in a programming language and evaluate the quality of the generated code.
- API access (optional): Use
curlin another terminal to test connectivity:
curl http://127.0.0.1:11434/api/chat -d '{"model": "gemma4:e2b","messages": [{"role": "user", "content": "Explain what a large language model is in one sentence"}]}'
If the service runs on a remote host or inside a container, replace the address with the corresponding IP, domain, or port-mapping address.
It is worth noting that these tests mainly verify whether the model runs normally. They do not measure the model’s overall capability. Small-parameter models still have clear limitations in Chinese expression, long-form writing, and complex reasoning. Errors are normal, and they should not be used directly for critical business decisions.
5. Common troubleshooting
During local deployment, the most common issues are usually the following:
- Cannot connect to the service: This is often caused by an incorrect listening address or a firewall rule that is not opened. First run
curl http://127.0.0.1:11434/api/tagson the machine running the inference runtime to confirm that the service itself is working. If access works locally but not from other devices, check the listening address and firewall rules. - Download interruption: Network fluctuations may cause download failures. Re-run
ollama run <model>; already downloaded parts are usually reused. - Out of memory: This may appear as a model-loading failure or as the service being terminated by the system. Try a more aggressive quantization tag, switch to a smaller model, or close programs that consume a large amount of memory.
- Slow responses: CPU-only inference is clearly limited by processor performance. If the computer has a dedicated GPU, confirm that the GPU driver and general-purpose compute stack are installed correctly. If necessary, adjust parameters such as thread count and context length through environment variables.
- Command not found: The installation script may not have added the program directory to the current user’s
PATH. You can run the command with its full path or add the directory to thePATHenvironment variable.
6. Further recommendations
- Updates and version management: The inference runtime is updated frequently. Regular upgrades can improve hardware compatibility and performance. Model files are stored independently in the cache directory, so upgrading the runtime usually does not affect models that have already been downloaded.
- Alternatives when hardware is insufficient: If local memory or VRAM is insufficient, besides choosing a more aggressive quantization, you can also use large models through cloud platforms, or use function calling to schedule cloud resources on demand. This can complement local models.
- Advanced use cases: Once the local service exposes a standard HTTP interface, it can be easily integrated into clients and applications that support custom model service addresses. On top of this, you can build knowledge-base Q&A, coding assistance, document summarization, and similar applications.
7. Conclusion
The core process of deploying an open-source large language model locally can be summarized in six steps: choose hardware, choose a model, install the runtime, configure the network, download the model, and verify it. As long as you follow the steps and pay attention to listening-address and firewall security settings, an ordinary developer can run the workflow on their own computer. Keep in mind that lightweight local models are best suited for scenarios such as offline availability, sensitive data, and cost sensitivity. For complex tasks, it is still better to combine them with larger cloud-hosted models.
