I was setting up a larger model with Ollama and I was thinking that since I do a lot of work with both Windows 11 and WSL, it doesn’t make sense to download 2 separate copies of the same model, taking up twice the drive resources, while possibly also introducing some versioning issues between the two.
I decided to make it so that both Ollama and WSL share the same downloaded model.
First, you need to set up environment variables that work on both sides.
if you don’t already have an OLLAMA_MODELS user environment variable in Windows, create it, and point it to your Windows Ollama models directory. This value can be found in your Ollama settings in the Ollama app under Model location.
Then you need to make a user environment variable in Windows that uses the WSL system WSLENV variable if it doesn’t exist and assign your OLLAMA_MODELS variable to it.
If WSLENV already exists, append OLLAMA_MODELS/p using a colon : as the delimiter. The /p ensures Windows paths are translated for WSL.
- If you just created it:
OLLAMA_MODELS/p - If you added it to an existing one
VARS_YOU_ALREADY_HAD:OLLAMA_MODELS/p
Note, you’ll need to click “OK” to accept and close all environment variable editing windows for it to take effect, as well as closing and reopening your terminal window for it to trigger in WSL
In WSL I needed to create a directory, and a link between the directories:
mkdir -p ~/ollama_models
here’s where that environment variable pays off immediately:
ln -s "$OLLAMA_MODELS" ~/ollama_models
Now you should be able to see your Ollama models in the ~/ollama_models directory in your WSL partition.
Next I added some environment variables to my terminal settings to make Ollama easier to use. I made one to make it easier if I ever needed the IP address of my Windows partition, and one so that I have the address for the Ollama base address.
replace 10.0.0.x in the below with your Windows IP address, and machine-name with the machine name of your Windows machine.
- note: this all assumes you have Windows and WSL communicating in the way that I do. See my blog post on how I set my inter-OS networking up.
echo "10.0.0.x machine-name" | sudo tee -a /etc/hosts
curl http://machine-name:11434
you should get Ollama is running
in ~/.bashrc
WINDOWS_IP=$(ipconfig.exe | grep -i "IPv4" | head -n 1 | awk '{print $NF}' | tr -d '\r')
export OLLAMA_IP="$WINDOWS_IP:11434"
and now you have handy environment variables to both your Windows IP address and the base address for your Ollama server running in Windows