로컬 AI/데이터 과학 환경
이 기사에서는 Ubuntu 26.04에서 완전한 로컬 AI 및 데이터 과학 개발 환경을 구축하는 방법을 다룹니다.
NVIDIA CUDA 환경 설정
GPU 가속 AI 모델을 실행하려면 먼저 NVIDIA 드라이버와 CUDA 툴킷을 설치해야 합니다.
NVIDIA 드라이버 설치
# Check the recommended driver version
ubuntu-drivers devices
# Install the recommended driver
sudo ubuntu-drivers autoinstall
# Or manually install the version reported by ubuntu-drivers devices
sudo apt install nvidia-driver-XXX -y
# Reboot
sudo reboot드라이버를 확인하십시오:
nvidia-smiCUDA 툴킷 설치
# Install via apt (Ubuntu repository version)
sudo apt install cuda-toolkit -y
# Verify
nvcc --version특정 CUDA 버전의 경우 NVIDIA 공식 저장소에서 설치합니다(Ubuntu 26.04은 ubuntu2604을 사용함).
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2604/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
# List available CUDA Toolkit versions in the repository
apt-cache search cuda-toolkit
# Install a specific version (replace XX-Y with an actual available version)
sudo apt install cuda-toolkit-XX-Y -yUbuntu 26.04는 이제 공식 저장소에 NVIDIA CUDA 툴킷을 제공하므로 sudo apt install cuda-toolkit이 직접 작동합니다. NVIDIA의 ubuntu2604 저장소는 특정 CUDA 버전이 필요할 때 유용합니다.
환경 변수를 구성합니다.
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrccuDNN 설치
sudo apt install libcudnn9-cuda-12 libcudnn9-dev-cuda-12 -yOllama: 로컬에서 대규모 언어 모델 실행
Ollama을 사용하면 Llama, Mistral 및 Gemma와 같은 대규모 언어 모델을 로컬에서 쉽게 실행할 수 있습니다.
Ollama 설치
curl -fsSL https://ollama.com/install.sh | sh기본 사용법
# Run a model (downloads automatically on first use)
ollama run llama3.2
# Run other models
ollama run mistral
ollama run gemma2
ollama run qwen2.5
ollama run deepseek-r1
# List downloaded models
ollama list
# Delete a model
ollama rm llama3.2
# View running models
ollama psOllama API
Ollama은 기본적으로 http://localhost:11434에서 실행되는 REST API를 제공합니다.
# Generate text
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"prompt": "Explain what machine learning is"
}'
# Chat conversation
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": [
{"role": "user", "content": "Hello"}
]
}'Open WebUI과 함께 사용
Open WebUI은 Ollama에 ChatGPT와 유사한 웹 인터페이스를 제공합니다.
docker run -d -p 3000:8080 \
--add-host=host.docker.internal:host-gateway \
-v open-webui:/app/backend/data \
--name open-webui \
ghcr.io/open-webui/open-webui:mainhttp://localhost:3000에서 액세스하세요.
Jupyter 노트북/실험실
Jupyter는 데이터 과학 및 기계 학습 분야에서 가장 널리 사용되는 대화형 개발 환경입니다.
JupyterLab 설치
# Ubuntu 26.04 blocks system-wide pip installs (PEP 668)
# Method 1: install as a standalone app with pipx
sudo apt install -y pipx
pipx ensurepath
pipx install jupyterlab
# Method 2: install inside a virtual environment
python3 -m venv ~/jupyter-env
source ~/jupyter-env/bin/activate
pip install jupyterlab notebook
# Method 3: use conda
conda install -c conda-forge jupyterlabJupyterLab 실행
jupyter lab브라우저가 자동으로 http://localhost:8888을 엽니다.
일반 커널 설치
# Install R kernel
sudo apt install r-base -y
R -e "install.packages('IRkernel'); IRkernel::installspec()"
# Install a kernel for a specific virtual environment
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"권장 Jupyter 확장
# Install in the same virtual environment as JupyterLab (or inject via pipx)
# pipx users can run: pipx inject jupyterlab jupyterlab-lsp python-lsp-server jupyterlab-git
pip install jupyterlab-lsp python-lsp-server
pip install jupyterlab-gitPyTorch
PyTorch은 현재 가장 널리 사용되는 딥러닝 프레임워크입니다.
PyTorch(GPU) 설치
# Install inside a virtual environment (PEP 668)
python3 -m venv ~/torch-env
source ~/torch-env/bin/activate
# pip install torch installs the wheel for the current CUDA by default;
# older drivers can pin a lower CUDA, e.g. cu126
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
# Using conda
conda install pytorch torchvision torchaudio pytorch-cuda=12.6 -c pytorch -c nvidiaPyTorch(CPU) 설치
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpuPyTorch GPU 지원 확인
import torch
print(f"PyTorch version: {torch.__version__}")
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"CUDA version: {torch.version.cuda}")
print(f"GPU device: {torch.cuda.get_device_name(0)}")
# Simple test
x = torch.rand(3, 3).cuda()
print(x)TensorFlow
TensorFlow 설치
# GPU version (auto-detects CUDA)
pip install tensorflow
# Verify
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"TensorFlow GPU 검증
import tensorflow as tf
print(f"TensorFlow version: {tf.__version__}")
print(f"GPU devices: {tf.config.list_physical_devices('GPU')}")
# Simple test
with tf.device('/GPU:0'):
a = tf.constant([[1.0, 2.0], [3.0, 4.0]])
b = tf.constant([[5.0, 6.0], [7.0, 8.0]])
c = tf.matmul(a, b)
print(c)공통 데이터 과학 패키지
# Activate a virtual environment first (PEP 668: no pip into the system Python)
python3 -m venv ~/ds-env && source ~/ds-env/bin/activate
pip install numpy pandas matplotlib seaborn scikit-learn scipy
pip install plotly bokeh altair
pip install polars # High-performance alternative to pandas
pip install xgboost lightgbm catboost # Gradient boosting frameworks완전한 AI 개발 환경 예시
권장되는 프로젝트 환경 설정 워크플로는 다음과 같습니다.
# Create project directory
mkdir ~/ai-project && cd ~/ai-project
# Create conda environment (pip is safe inside a conda environment)
conda create -n ai python=3.13 -y
conda activate ai
# Install core libraries (current CUDA by default; older drivers can pin cu126)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
pip install transformers datasets accelerate
pip install jupyterlab
pip install numpy pandas matplotlib scikit-learn
# Launch Jupyter
jupyter lab허깅 페이스 트랜스포머 사용
pip install transformers datasets acceleratefrom transformers import pipeline
# Text generation
generator = pipeline("text-generation", model="gpt2")
result = generator("The future of artificial intelligence is", max_length=50)
print(result)
# Sentiment analysis
classifier = pipeline("sentiment-analysis")
result = classifier("This product is amazing")
print(result)GPU 사용량 모니터링
# Real-time monitoring
watch -n 1 nvidia-smi
# Use nvitop (more visually appealing) -- install as a standalone CLI with pipx
pipx install nvitop
nvitop
# Use gpustat
pipx install gpustat
gpustat -i 1로컬 AI 환경이 설정되면 Ubuntu 26.04에서 다양한 대규모 언어 모델과 딥 러닝 작업을 실행할 준비가 되었습니다.