Skip to Content
DocsDevelopmentLocal AI / Data Science

Local AI / Data Science Environment

This article covers how to build a complete local AI and data science development environment on Ubuntu 26.04.

NVIDIA CUDA Environment Setup

Running GPU-accelerated AI models requires installing NVIDIA drivers and the CUDA toolkit first.

Install NVIDIA Drivers

# 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

Verify the driver:

nvidia-smi

Install CUDA Toolkit

# Install via apt (Ubuntu repository version) sudo apt install cuda-toolkit -y # Verify nvcc --version

For a specific CUDA version, install from the NVIDIA official repository (Ubuntu 26.04 uses 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 -y
Note

Ubuntu 26.04 now ships the NVIDIA CUDA Toolkit in its official repositories, so sudo apt install cuda-toolkit works directly. NVIDIA’s ubuntu2604 repository remains useful when you need a specific CUDA version.

Configure environment variables:

echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc

Install cuDNN

sudo apt install libcudnn9-cuda-12 libcudnn9-dev-cuda-12 -y

Ollama: Run Large Language Models Locally

Ollama lets you easily run large language models like Llama, Mistral, and Gemma locally.

Install Ollama

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

Basic Usage

# 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 ps

Ollama API

Ollama provides a REST API, running by default at http://localhost:11434:

# 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"} ] }'

Use with Open WebUI

Open WebUI provides a ChatGPT-like web interface for Ollama:

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:main

Access it at http://localhost:3000.

Jupyter Notebook / Lab

Jupyter is the most popular interactive development environment in data science and machine learning.

Install 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 jupyterlab

Launch JupyterLab

jupyter lab

Your browser will automatically open http://localhost:8888.

Install Common Kernels

# 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)"
# 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-git

PyTorch

PyTorch is currently the most popular deep learning framework.

Install 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 nvidia

Install PyTorch (CPU)

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

Verify PyTorch GPU Support

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

Install 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 Verification

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)

Common Data Science Packages

# 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

Complete AI Development Environment Example

Here’s a recommended project environment setup workflow:

# 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

Using Hugging Face Transformers

pip install transformers datasets accelerate
from 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)

Monitor GPU Usage

# 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

With your local AI environment set up, you’re ready to run various large language models and deep learning tasks on Ubuntu 26.04.

Last updated on