AI LLM
Ranjithkumar  

Run LLMs Locally Using Ollama

In recent years, large language models (LLMs) have revolutionized various applications, from chatbots to code generation and research. However, many of these models require cloud-based APIs, raising concerns about privacy, latency, and cost.

Ollama is a powerful tool that allows you to run LLMs locally on your machine without relying on external APIs. It simplifies downloading, managing, and using models like LLaMA, Mistral, and Gemma while ensuring optimal performance even on consumer hardware.

Why Run LLMs Locally?

Running LLMs locally comes with several advantages:

  1. Privacy & Security – No data leaves your machine, ensuring confidentiality.
  2. Lower Latency – No network requests mean faster responses.
  3. Reduced Cost – Avoid recurring API costs.
  4. Customization – Modify and fine-tune models for specific needs.

Getting Started with Ollama

1. Install Ollama

macOS and Linux

Ollama supports macOS and Linux. Installing it is straightforward:

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

Windows

Ollama can be installed on Windows via WSL2. Follow these steps:

  1. Install Windows Subsystem for Linux (WSL2).
  2. Open a WSL terminal and run:
curl -fsSL https://ollama.com/install.sh | sh

2. Verify Installation

Once installed, check if Ollama is working:

ollama

This should display available commands.

3. Download and Run a Model

Before running a model, you need to pull it:

ollama pull mistral

This downloads the model to your system.

To run the model interactively:

ollama run mistral

4. Running a Model with Custom Prompts

To use a model with a custom prompt:

ollama run mistral "What is the capital of France?"

Ollama will return the answer instantly.

Managing and Customizing Models

1. Listing Available Models

Check which models are installed:

ollama list

2. Creating a Custom Model

You can define custom models using Modelfile. For example:

FROM mistral

PARAMETER temperature 0.7

SYSTEM "You are an AI assistant. Answer concisely."

Save this as Modelfile and create a new model:

ollama create my-mistral -f Modelfile

Run your custom model:

ollama run my-mistral

Using Ollama in Applications

Ollama provides an API for integrating local LLMs into applications.

Example: Running a Query via API

Start the API server:

ollama serve

Then, use Python to interact with it:

import requests

response = requests.post("http://localhost:11434/api/generate", json={
    "model": "mistral",
    "prompt": "Explain quantum computing in simple terms."
})
print(response.json()["response"])

Performance Considerations

While running LLMs locally is convenient, it depends on your hardware. Here are some recommendations:

  • RAM: At least 8GB, but 16GB+ is ideal.
  • GPU: Models run faster with a dedicated GPU (e.g., NVIDIA with CUDA support).
  • Storage: Some models require multiple GBs of disk space.

For better performance, use quantized models (smaller versions optimized for speed and memory usage).

Conclusion

Ollama makes running LLMs locally simple and efficient, providing privacy, speed, and cost advantages. Whether you’re a developer, researcher, or enthusiast, it offers an excellent alternative to cloud-based AI services.

Start experimenting with Ollama today and unlock the power of local AI!

For more details, check out the official documentation: Ollama.

Leave A Comment