---
title: "Deploy JupyterLab | Use Open Source Models in Notebooks Directly"
description: "[Jun '26] Host any LLM Model using Ollama & Use in Jupyter Notebooks"
category: "AI/ML"
url: https://railway.com/deploy/ollama-jupyter-lab-or-run-local-llms-fro
---

# Deploy JupyterLab | Use Open Source Models in Notebooks Directly

[Jun '26] Host any LLM Model using Ollama & Use in Jupyter Notebooks

**[Deploy JupyterLab | Use Open Source Models in Notebooks Directly on Railway](https://railway.com/template/ollama-jupyter-lab-or-run-local-llms-fro)**

- **Creator:** Heimdall
- **Category:** AI/ML
- **Total deploys:** 5

## Template content

### Jupyter https://devicons.railway.app/jupyter

- **Image:** jupyter/all-spark-notebook
- **Start command:** `/bin/sh -c " \     if [ -n \"${EXTRA_PIP_PACKAGES}\" ]; then \         echo \"Installing extra pip packages: ${EXTRA_PIP_PACKAGES}\"; \         pip install --no-cache-dir ${EXTRA_PIP_PACKAGES}; \     else \         echo \"No extra pip packages to install\"; \     fi && \     (echo ${JUPYTER_PASSWORD}; echo ${JUPYTER_PASSWORD}) | jupyter server password 2>&1 && \     chown ${NB_UID} /home/jovyan/.jupyter/jupyter_server_config.json && \     rm -rf ${RAILWAY_VOLUME_MOUNT_PATH}/lost+found && \     chown -R ${NB_UID} ${RAILWAY_VOLUME_MOUNT_PATH} && \     start.sh run-one-constantly jupyter lab 2>&1 \ "`
- **Public domain:** Yes

### Ollama https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/ollama-dark.svg

- **Image:** ollama/ollama
- **Start command:** `bash -c "ollama serve & sleep 5 && ollama pull $OLLAMA_DEFAULT_MODELS && wait"`
- **Public domain:** Yes

## Documentation

![Using Ollama in jupyter notebook](https://res.cloudinary.com/asset-cloudinary/image/upload/v1769667334/ollama_in_notebook_zsqg8l.png)

# Deploy and Host Ollama + Jupyter Lab | Run Local LLMs from Jupyter on Railway

Ollama + Jupyter Lab lets you run **local large language models (LLMs)** and interact with them directly from Jupyter notebooks. This template deploys Ollama as a model server and JupyterLab as a notebook environment, connected via private networking and backed by persistent storage.


## ⚡ Quick Usage Cheat Sheet (Important)

Your Ollama server talks to Jupyter through a private connection. Here's how to use it:

```python
import os
base_url = os.getenv("OLLAMA_BASE_URL")
```

#### 📋 See what models you have

```python
# Using requests
requests.get(f"{base_url}/api/tags").json()

# Using ollama library
client = ollama.Client(host=base_url)
client.list()
```

#### ⬇️ Download a new model

```python
# Using requests
requests.post(f"{base_url}/api/pull", json={"name": "qwen2.5:0.5b"})

# Using ollama library
client.pull("qwen2.5:0.5b")
```

#### 💬 Chat with your AI model

```python
# Using requests
response = requests.post(
    f"{base_url}/api/generate",
    json={"model": "qwen2.5:0.5b", "prompt": "Hello", "stream": False}
).json()["response"]

# Using ollama library
response = client.generate(model="qwen2.5:0.5b", prompt="Hello", stream=False)["response"]
```

#### 🗑️ Remove a model you don't need

```python
# Using requests
requests.delete(f"{base_url}/api/delete", json={"name": "qwen2.5:0.5b"})

# Using ollama library
client.delete("qwen2.5:0.5b")
```

---


## 🎯 About Hosting Ollama + Jupyter Lab | Run Local LLMs from Jupyter

This setup gives you **two connected services**:

**Ollama Server** - Downloads and runs open-source AI models locally  
**JupyterLab** - Your interactive coding environment for notebooks

They talk to each other through Railway's **private network**, so your AI models stay completely private. Everything is saved to **persistent storage**, meaning your notebooks and downloaded models stick around even when you redeploy.

Perfect for learning, experimenting, and building AI apps without relying on paid API services.

---

##💡 Common Use Cases

* 🧪 Test and compare different open-source AI models
* ✍️ Fine-tune your prompts and experiment with responses
* 🔒 Work with AI models completely offline and private
* 📊 Build AI prototypes and proof-of-concepts
* 🎓 Learn how language models work hands-on
* 🛠️ Develop AI applications without API costs

## Dependencies for Ollama + Jupyter Lab | Run Local LLMs from Jupyter Hosting

* **Railway** for deployment and private networking
* **Ollama** for running local LLM models
* **JupyterLab** for interactive notebooks
* **Python 3** with `requests` or `ollama` library

### 📚 Deployment Dependencies

* Ollama documentation: [https://ollama.com](https://ollama.com)
* Ollama model library: [https://ollama.com/library](https://ollama.com/library)
* JupyterLab: [https://jupyter.org](https://jupyter.org)


### 🔍 Implementation Details 

* Ollama pulls models on startup using the `OLLAMA_DEFAULT_MODELS` environment variable.
* Jupyter connects to Ollama using `OLLAMA_BASE_URL`, injected automatically via Railway.
* Models and notebooks are stored on separate persistent volumes to avoid data loss.
* All model inference happens inside the Ollama service; Jupyter only sends requests.


## ⚙️ Customize Your Setup

You can control everything through environment variables—no code changes needed.

### Jupyter Settings

**`OLLAMA_BASE_URL`** 🔗  
The private URL Jupyter uses to talk to Ollama. Keep this as-is for everything to work.

**`EXTRA_PIP_PACKAGES`** 📦  
Add extra Python libraries you need (like `pandas`, `langchain`, or `transformers`). They'll install automatically at startup.

**`JUPYTER_PASSWORD`** 🔐  
Protects your JupyterLab interface. Set this to something secure.

---

### Ollama Settings

**`OLLAMA_DEFAULT_MODELS`** 🤖  
List the AI models you want downloaded automatically when Ollama starts. Just separate them with commas:

```
deepseek-r1:1.5b,qwen2.5:0.5b,llama3:8b
```

This way you **control which AI models are ready to use** without running any commands or notebooks manually.

**`OLLAMA_ORIGINS`** ✅  
Already configured to allow access from Jupyter.

---


	
## ❓ Common Questions

**Do I need an API key from OpenAI or Anthropic?**  
Nope! Everything runs locally on your own infrastructure. No external API needed.

**Will I lose my notebooks when I redeploy?**  
No way. Just save your work in the `/work` directory and it'll stick around through redeployments.

**Do AI models re-download every time?**  
Nope. Once downloaded, they're stored permanently until you delete them.

**Can I switch to different AI models later?**  
Absolutely. Download new ones from your notebook or update `OLLAMA_DEFAULT_MODELS` and redeploy.

**Can I make Ollama publicly accessible?**  
By default it's private (more secure), but you can configure it for public access if needed. Reach out if you need help with this.

---
## 🆚 Ollama vs Other Options

**🏠 Ollama (This Setup)**
* Run AI models on your own infrastructure
* Super simple setup and model management
* No external dependencies or API costs
* Great for learning and development

**☁️ Cloud AI APIs (OpenAI, Claude, etc.)**
* No setup required
* Pay per use
* Your data goes to their servers

**⚙️ Custom Model Servers (vLLM, TGI)**
* Maximum control and performance
* Complex setup and maintenance
* Best for large production systems

**Ollama hits the sweet spot** for local AI development, learning, and controlled experiments—especially when paired with JupyterLab.

---

## Why Deploy Ollama + Jupyter Lab | Run Local LLMs from Jupyter on Railway?


Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Ollama + Jupyter Lab | Run Local LLMs from Jupyter on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.
- [Hermes Agent | OpenClaw Alternative with Dashboard](https://railway.com/deploy/hermes-agent-or-openclaw-alternative-wit) — Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

Open this page in a browser: https://railway.com/deploy/ollama-jupyter-lab-or-run-local-llms-fro
