Flox creates reproducible development environments that work the same on any machine. This guide shows you how to use it to run a local AI model.
Install Flox
Review the install script first (good security practice):
curl -LsSf https://gist.githubusercontent.com/noor-latif/3f64834ae832d8fbceac6214a2cc5e70/raw/aec3d6076e0e601a08ccf75de6c911ba61222750/flox-install.sh | less
Then install:
curl -LsSf https://gist.githubusercontent.com/noor-latif/3f64834ae832d8fbceac6214a2cc5e70/raw/aec3d6076e0e601a08ccf75de6c911ba61222750/flox-install.sh | sh
Set Up Your Environment
Initialize Flox in your project folder:
flox init
flox activate
Install Python and Ollama:
flox install python3
flox install ollama
Configure Ollama as a Service
Edit your Flox environment:
flox edit
Add these configurations:
Under [services]:
ollama.command = "ollama serve"
Under [vars] (to make the API accessible on your network):
OLLAMA_HOST = "0.0.0.0:11434"
Start Everything
Activate Flox with services:
flox activate -s
The -s flag automatically starts services (like Ollama) when you enter the environment.
Run an AI Model
Deploy a lightweight model:
ollama run tinyllama
This starts an interactive chat. Press Ctrl+D to exit. The model API remains available at http://localhost:11434 while the service is running.
Verify Service Status
Check if Ollama is running:
flox services status
If you need to manually stop/start:
flox services stop
flox services start
Why This Works Better
Flox handles the complexity automatically. When you exit the environment with exit, Flox cleanly stops all services. No orphaned background processes to track down.
Bonus: Auto-Activate with Direnv
Tired of forgetting flox activate? Install direnv to automatically activate environments when you cd into project folders.
Create a default environment and install direnv on the home folder level:
flox init -d $HOME
flox install -d $HOME direnv
Add to your ~/.bashrc (or ~/.zshrc for zsh, etc...):
eval "$(flox activate -d $HOME)"
eval "$(direnv hook bash)" # bash or zsh/fish/tcsh/starship
Reload your shell:
source ~/.bashrc
In any Flox project, create an .envrc file:
echo 'use flox' > .envrc && direnv allow
Now the environment activates automatically when you enter the directory and deactivates when you leave.
Resources:
Top comments (0)