Ollama 정리 - 설치 및 사용

이민재·2026년 4월 20일

Ollama 정리 - 설치 및 사용


목차

  1. Ollama란?
  2. Windows 설치
  3. 모델 설치 및 실행
  4. CLI 주요 명령어
  5. REST API 사용법
  6. Python 라이브러리
  7. GUI 앱 연동
  8. 시스템 요구사항 및 GPU 가속

Ollama란?

Ollama는 로컬 환경에서 LLM(대형 언어 모델)을 손쉽게 실행할 수 있는 오픈소스 도구입니다.

  • 인터넷 연결 없이 AI 모델 실행 가능
  • ChatGPT와 유사한 채팅 인터페이스 제공
  • REST API로 앱 연동 가능
  • 완전 무료, 데이터가 외부로 나가지 않음

Windows 설치

1. 설치 파일 다운로드

공식 사이트에서 Windows 설치 파일을 받습니다.

https://ollama.com/download/windows

2. 설치 실행

OllamaSetup.exe 실행 → Install 클릭

💡 Windows Defender 경고가 뜨면 "추가 정보" → "실행" 클릭

설치 완료 후 시스템 트레이(우측 하단)에 라마 아이콘이 생성됩니다.

3. 설치 확인

PowerShell 또는 명령 프롬프트(cmd)를 열고 확인합니다.

ollama --version

모델 설치 및 실행

추천 모델 목록 (한국어 지원 포함)

모델크기특징
gemma3:4b3.3GB입문 추천, 성능 균형
llama3.2:3b2.0GB경량, 빠른 응답
qwen2.5:7b4.7GB한국어 성능 강점
mistral:7b4.1GB영어 성능 강점

모델 실행 (처음 실행 시 자동 다운로드)

ollama run gemma3:4b

다운로드 완료 후 >>> 프롬프트가 나타나면 바로 대화할 수 있습니다.

>>> 안녕하세요! 파이썬 리스트 컴프리헨션을 설명해줘

종료하려면 /bye 또는 Ctrl+D를 입력합니다.


CLI 주요 명령어

# 설치된 모델 목록 확인
ollama list

# 모델 다운로드만 (실행 없이)
ollama pull llama3.2:3b

# 모델 삭제
ollama rm gemma3:4b

# 현재 실행 중인 모델 확인
ollama ps

# 모델 상세 정보
ollama show gemma3:4b

# API 서버 수동 실행
ollama serve

REST API 사용법

Ollama를 설치하면 백그라운드에서 자동으로 API 서버가 실행됩니다.

  • 기본 주소: http://localhost:11434
  • 별도 설정 없이 바로 호출 가능

텍스트 생성 (generate)

curl http://localhost:11434/api/generate \
  -d '{
    "model": "gemma3:4b",
    "prompt": "하늘은 왜 파란가요?",
    "stream": false
  }'

채팅 (chat)

curl http://localhost:11434/api/chat \
  -d '{
    "model": "gemma3:4b",
    "messages": [
      {"role": "user", "content": "안녕하세요!"}
    ],
    "stream": false
  }'

응답 구조

{
  "model": "gemma3:4b",
  "message": {
    "role": "assistant",
    "content": "안녕하세요! 무엇을 도와드릴까요?"
  }
}

Python 라이브러리

설치

pip install ollama

기본 채팅

import ollama

response = ollama.chat(
    model="gemma3:4b",
    messages=[
        {"role": "system", "content": "당신은 친절한 AI 도우미입니다."},
        {"role": "user", "content": "파이썬 리스트 컴프리헨션을 설명해줘"}
    ]
)

print(response["message"]["content"])

멀티턴 대화

이전 메시지를 messages 리스트에 누적해서 넘기면 맥락이 유지됩니다.

import ollama

messages = []

def chat(user_input):
    messages.append({"role": "user", "content": user_input})
    response = ollama.chat(model="gemma3:4b", messages=messages)
    assistant_msg = response["message"]["content"]
    messages.append({"role": "assistant", "content": assistant_msg})
    return assistant_msg

print(chat("내 이름은 홍길동이야"))
print(chat("내 이름이 뭐라고 했지?"))  # 맥락 유지됨

스트리밍 출력

import ollama

stream = ollama.chat(
    model="gemma3:4b",
    messages=[{"role": "user", "content": "파이썬의 장점 5가지"}],
    stream=True
)

for chunk in stream:
    print(chunk["message"]["content"], end="", flush=True)
print()

단일 프롬프트 생성 (generate)

response = ollama.generate(
    model="gemma3:4b",
    prompt="하늘이 파란 이유를 한 문장으로 설명해줘",
    system="간결하게 답변하세요",
    options={"temperature": 0.7}
)

print(response["response"])

텍스트 임베딩 (벡터 생성)

RAG, 유사도 검색, 문서 분류 등에 활용합니다.

# 임베딩 전용 모델 먼저 설치 필요
# ollama pull nomic-embed-text

result = ollama.embeddings(
    model="nomic-embed-text",
    prompt="안녕하세요"
)

vector = result["embedding"]
print(f"벡터 차원 수: {len(vector)}")

비동기 (AsyncClient)

FastAPI, aiohttp 등 비동기 웹 프레임워크에서 사용합니다.

import asyncio
import ollama

async def main():
    client = ollama.AsyncClient()
    response = await client.chat(
        model="gemma3:4b",
        messages=[{"role": "user", "content": "안녕!"}]
    )
    print(response["message"]["content"])

asyncio.run(main())

모델 관리

import ollama

# 설치된 모델 목록
models = ollama.list()
for m in models["models"]:
    print(m["name"], m["size"])

# 모델 다운로드
ollama.pull("llama3.2:3b")

# 모델 정보 조회
info = ollama.show("gemma3:4b")
print(info["modelfile"])

# 모델 삭제
ollama.delete("gemma3:4b")

원격 서버 연결

import ollama

# 기본값은 http://localhost:11434
client = ollama.Client(host="http://192.168.1.100:11434")

response = client.chat(
    model="gemma3:4b",
    messages=[{"role": "user", "content": "테스트"}]
)
print(response["message"]["content"])

GUI 앱 연동

Open WebUI (추천)

ChatGPT와 유사한 웹 인터페이스를 제공합니다. Docker가 필요합니다.

docker run -d -p 3000:8080 `
  --add-host=host.docker.internal:host-gateway `
  -v open-webui:/app/backend/data `
  ghcr.io/open-webui/open-webui:main

설치 후 브라우저에서 http://localhost:3000 접속

VS Code 연동 (Continue 확장)

  1. VS Code Marketplace에서 Continue 확장 설치
  2. config.json에서 Ollama 모델 지정
  3. 코드 자동완성, 채팅 등 GitHub Copilot처럼 사용 가능

시스템 요구사항 및 GPU 가속

권장 사양

항목최소권장
RAM8GB16GB (7B 모델 기준)
저장소모델당 2~8GBSSD 권장
OSWindows 10 64-bitWindows 11
GPU없어도 동작 (CPU)NVIDIA GPU (CUDA)

GPU 가속

NVIDIA GPU가 있으면 설치 즉시 CUDA 가속이 자동 적용됩니다. 별도 설정이 필요 없습니다.

💡 CPU 대비 5~20배 빠른 응답 속도를 경험할 수 있습니다.

GPU 사용 여부를 확인하려면:

ollama ps

실행 중인 모델 옆에 GPU 사용량이 표시됩니다.


마무리

Ollama는 로컬 AI 환경을 구성하는 가장 빠른 방법입니다. Python 라이브러리와 REST API를 통해 다양한 애플리케이션에 LLM을 손쉽게 연동할 수 있고, Open WebUI를 통해 ChatGPT와 동일한 사용 경험도 얻을 수 있습니다.


참고: Ollama 공식 문서 | Ollama GitHub

profile
초보 개발자

0개의 댓글