ollama: command not found inside WSL means the Linux side has no program called
ollama. Ollama for Windows installs ollama.exe, and WSL can run it, but Linux
never adds .exe to a name for you. Type ollama.exe, or install the Linux
build inside the distribution.
The quick route is ollama.exe list, or alias ollama=ollama.exe in
~/.bashrc, which uses the Windows app and the models you already pulled there. The other
route, curl -fsSL https://ollama.com/install.sh | sh, installs a separate Linux server
with its own models.
The error
PS> wsl -d fix5-ollama -u root -- ollama list
/bin/bash: line 1: ollama: command not found
$ ollama list
ollama: command not found
The first form is a command sent from PowerShell, the second is an interactive shell inside the
distribution. Both exited with code 127, the shell's code for a command it cannot find.
fix5-ollama is the throwaway distribution made for the test.
Why it happens
Bash looks for a file named exactly ollama in each folder on PATH. WSL adds
the Windows PATH to the Linux one, and the Ollama folder is on the Windows
PATH, so the program was in reach all along under its Windows name:
$ command -v ollama.exe
/mnt/c/Users/.../AppData/Local/Programs/Ollama/ollama.exe
Linux runs that file through WSL interop, which was switched on here
(/proc/sys/fs/binfmt_misc/WSLInterop read enabled). What Linux will not do
is match ollama to ollama.exe. A Linux client talking to the Windows server
is not a way round it either: curl to 127.0.0.1:11434 from the distribution
said Couldn't connect to server, because in the NAT networking mode this WSL used, the
distribution's loopback is its own and the Windows app listens on the Windows one.
ollama.exe works because it runs as a Windows process.
The fix
$ ollama.exe --version
ollama version is 0.40.6
$ ollama.exe list
NAME ID SIZE MODIFIED
qwen2.5:3b 357c53fb659c 1.9 GB 17 minutes ago
llama3.1:8b 46e0c10c039e 4.9 GB 4 weeks ago
$ ollama.exe run qwen2.5:3b "Reply with the single word ready."
ready
$ echo "alias ollama=ollama.exe" >> ~/.bashrc
$ type ollama
ollama is aliased to `ollama.exe'
$ ollama list
NAME ID SIZE MODIFIED
qwen2.5:3b 357c53fb659c 1.9 GB 18 minutes ago
The lists are shortened to two rows and one row of five. The alias works in shells started after the
line was added; run source ~/.bashrc in the one you have open. This route keeps one
server and one set of models, on Windows.
Install the Linux build instead when Linux programs inside the distribution must call the API at
localhost:11434, such as a .NET or Python app you run in WSL. That server is separate,
with its own models folder, so you pull your models again for it, and on a fresh Ubuntu the installer
first needs zstd.
How it was reproduced
WSL 2.7.10 on Windows 11, with Ollama 0.40.6 running as the Windows tray app. A throwaway Ubuntu
24.04.5 distribution was created with wsl --install Ubuntu-24.04 --name fix5-ollama
--no-launch and used as root, with nothing installed in it. The capture script ran bash
interactively without a terminal, so each command also printed a job-control warning that is left out
here; nothing else changed. The fix was confirmed with ollama.exe and with the alias,
and the distribution was unregistered afterwards.
Frequently asked
- Can WSL use Ollama installed on Windows?
- Yes, by running ollama.exe instead of ollama. WSL puts the Windows PATH on the Linux PATH, so ollama.exe list and ollama.exe run work from a WSL terminal and use the Windows app's server and models.
- Why can't WSL reach Ollama on localhost:11434?
- In NAT networking mode the distribution has its own loopback, and the Windows app listens on the Windows loopback. In the test, curl to 127.0.0.1:11434 from the distribution could not connect, while ollama.exe worked because it runs as a Windows process.
- Should I install Ollama inside WSL or use the Windows app?
- Use ollama.exe if you only need the command line and want one set of models. Install the Linux build inside WSL when Linux programs there must call the API at localhost:11434; that server has its own models folder, so you pull models again for it.
More decoded errors in the Fixes category. For the Linux route, step by step and tested on a bare Ubuntu 24.04, see Install Ollama on Linux and WSL.