Set Ollama default context size on Linux

Just as simply as this:

sudo systemctl edit ollama.service

Then add the following lines (to set to 64k tokens context size):

[Service]
Environment="OLLAMA_CONTEXT_LENGTH=64000"

Save and exit, then restart Ollama:

sudo service ollama restart

And you’re done:

ollama ps
NAME ID SIZE PROCESSOR CONTEXT UNTIL
gpt-oss:20b 17052f91a42e 15 GB 100% GPU 64000 4 minutes from now

Note: Tested on Ubuntu 24.04 with Ollama 0.15

That’s it, Enjoy!

Unknown's avatar

About Ahmed Tawfik

Cybersecurity Professional, Systems Engineer, OSS & Linux Geek
This entry was posted in Ollama and tagged , , , . Bookmark the permalink.

Leave a comment