[GH-ISSUE #1501] macOS environment variable not working #47324

Closed
opened 2026-04-28 03:35:33 -05:00 by GiteaMirror · 10 comments
Owner

Originally created by @brandoncarl on GitHub (Dec 13, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/1501

Hello - thanks for the great repository. I wanted to alert you to the fact that the OLLAMA_MODELS path appears to be having no impact. This is true for pull, rull and serving.

$ echo $OLLAMA_MODELS
(prints appropriate directory)

$ ollama run <model>
(downloads to ~/.ollama/..)

$ OLLAMA_MODELS=<directory> run <model>
(downloads to ~/.ollama/...)
Originally created by @brandoncarl on GitHub (Dec 13, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/1501 Hello - thanks for the great repository. I wanted to alert you to the fact that the OLLAMA_MODELS path appears to be having no impact. This is true for `pull`, `rull` and serving. ``` $ echo $OLLAMA_MODELS (prints appropriate directory) $ ollama run <model> (downloads to ~/.ollama/..) $ OLLAMA_MODELS=<directory> run <model> (downloads to ~/.ollama/...) ```
Author
Owner

@marabgol commented on GitHub (Dec 13, 2023):

I have the same issue, the models fills user home, I set OLLAMA_MODELS somewhere else but it still usees ~/.ollama, thanks

<!-- gh-comment-id:1854169540 --> @marabgol commented on GitHub (Dec 13, 2023): I have the same issue, the models fills user home, I set OLLAMA_MODELS somewhere else but it still usees ~/.ollama, thanks
Author
Owner

@easp commented on GitHub (Dec 13, 2023):

Models are downloaded by the ollama server, which is probably running as a different user than ollama run, and may be running on a different machine, so the environment variables set for ollama run aren't available and may not even make sense for the ollama server.

Two issues. First is the scope of environment variables. Setting them in a shell only sets them for that shell instance and its descendants. It's not clear (to me) that there is a mechanism for setting system-wide (or user-wide) environment variables on MacOS. Second, if such a mechanism exists, it's not clear that the Ollama.app on MacOS even checks those.

The work-around is to use ollama serve instead of the Ollama app to run the Ollama server.

There is clearly room for improvement.

<!-- gh-comment-id:1854401485 --> @easp commented on GitHub (Dec 13, 2023): Models are downloaded by the ollama server, which is probably running as a different user than `ollama run`, and may be running on a different machine, so the environment variables set for `ollama run` aren't available and may not even make sense for the ollama server. Two issues. First is the scope of environment variables. Setting them in a shell only sets them for that shell instance and its descendants. It's not clear (to me) that there is a mechanism for setting system-wide (or user-wide) environment variables on MacOS. Second, if such a mechanism exists, it's not clear that the Ollama.app on MacOS even checks those. The work-around is to use `ollama serve` instead of the Ollama app to run the Ollama server. There is clearly room for improvement.
Author
Owner

@marabgol commented on GitHub (Dec 13, 2023):

I modified server/modelpath.go and compiled , ./ollama serve seems working,
do we have access to Ollama.app source code ?

<!-- gh-comment-id:1854447654 --> @marabgol commented on GitHub (Dec 13, 2023): I modified server/modelpath.go and compiled , ./ollama serve seems working, do we have access to Ollama.app source code ?
Author
Owner

@easp commented on GitHub (Dec 13, 2023):

@marabgol I believe the app source is here: https://github.com/jmorganca/ollama/tree/main/app

<!-- gh-comment-id:1854843182 --> @easp commented on GitHub (Dec 13, 2023): @marabgol I believe the app source is here: https://github.com/jmorganca/ollama/tree/main/app
Author
Owner

@marabgol commented on GitHub (Dec 14, 2023):

Thanks @easp
the home variable appears in 4 js files

<!-- gh-comment-id:1854948577 --> @marabgol commented on GitHub (Dec 14, 2023): Thanks @easp the home variable appears in 4 js files
Author
Owner

@mxyng commented on GitHub (Jan 22, 2024):

OLLAMA_MODELS should work when set with launchctl setenv. See the FAQ for more details. Make sure to restart Ollama.app after making changes for changes to take effect.

<!-- gh-comment-id:1905031047 --> @mxyng commented on GitHub (Jan 22, 2024): `OLLAMA_MODELS` should work when set with `launchctl setenv`. See the [FAQ](https://github.com/jmorganca/ollama/blob/main/docs/faq.md#where-are-models-stored) for more details. Make sure to restart Ollama.app after making changes for changes to take effect.
Author
Owner

@lloiacono commented on GitHub (Feb 25, 2024):

OLLAMA_MODELS should work when set with launchctl setenv. See the FAQ for more details. Make sure to restart Ollama.app after making changes for changes to take effect.

This needs to be setup on each reboot of the system. To make this changes persist reboots on OSX creating a launch agent or daemon might do the job. For example creating a file /Library/LaunchAgents/setenv.OLLAMA_MODELS.plist with the following content

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Ollama models env var</key>
   <string>setenv.OLLAMA_MODELS</string>
   <key>ProgramArguments</key>
   <array>
      <string>launchctl</string>
      <string>setenv</string>
      <string>OLLAMA_MODELS</string>
      <string>/some/folder</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
</dict>
</plist>
<!-- gh-comment-id:1962974101 --> @lloiacono commented on GitHub (Feb 25, 2024): > `OLLAMA_MODELS` should work when set with `launchctl setenv`. See the [FAQ](https://github.com/jmorganca/ollama/blob/main/docs/faq.md#where-are-models-stored) for more details. Make sure to restart Ollama.app after making changes for changes to take effect. This needs to be setup on each reboot of the system. To make this changes persist reboots on OSX creating a launch agent or daemon might do the job. For example creating a file `/Library/LaunchAgents/setenv.OLLAMA_MODELS.plist` with the following content ```<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Ollama models env var</key> <string>setenv.OLLAMA_MODELS</string> <key>ProgramArguments</key> <array> <string>launchctl</string> <string>setenv</string> <string>OLLAMA_MODELS</string> <string>/some/folder</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> ```
Author
Owner

@jscalo commented on GitHub (May 2, 2024):

A good workaround is to

  • Move the existing .ollama directory to the desired alternate location
  • Make a symlink from the new location to the default location: ln -s <new .ollama location> ~/.ollama
<!-- gh-comment-id:2089402149 --> @jscalo commented on GitHub (May 2, 2024): A good workaround is to - Move the existing `.ollama` directory to the desired alternate location - Make a symlink from the new location to the default location: `ln -s <new .ollama location> ~/.ollama`
Author
Owner

@soakes commented on GitHub (Jan 11, 2025):

Today while expermenting with my new Apple Silicon, I have ran into this exact same issue. I have tried various ways to resolve it and the best way I have found is to create a new plist file and not run the brew services version. This will then allow for upgrades not to interfear with Ollama and your ENV changes.

Hope this helps people with the same issue.

Below are taken from my notes:

How to configure Ollama with Custom Environment Variables on macOS

Overview

This guide explains how to configure Ollama to listen on all network interfaces (0.0.0.0) on macOS by creating a custom launch agent configuration. This method ensures the configuration persists through Ollama updates, unlike using the default brew services approach.

Prerequisites

  • Ollama installed via Homebrew
  • Administrative access to your macOS system

Configuration Steps

1. Create Custom Launch Agent Configuration

Create a new launch agent configuration file in your user's LaunchAgents directory:

cat << 'EOF' > ~/Library/LaunchAgents/com.ollama.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.ollama</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/homebrew/bin/ollama</string>
        <string>serve</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
        <key>OLLAMA_HOST</key>
        <string>0.0.0.0</string>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>
EOF

2. Load the Launch Agent

After creating the configuration file, load it using launchctl:

launchctl load ~/Library/LaunchAgents/com.ollama.plist

Configuration Breakdown

The launch agent configuration includes several important components:

  • Label: Unique identifier for the launch agent
  • ProgramArguments: Specifies the Ollama executable path and the 'serve' command
  • EnvironmentVariables: Sets OLLAMA_HOST to '0.0.0.0' to listen on all interfaces
  • RunAtLoad: Ensures the service starts automatically at login
  • KeepAlive: Keeps the service running continuously

Notes

  • No system reboot is required after loading the configuration
  • This configuration will persist through Ollama updates
  • The service will automatically start when you log in

Troubleshooting

If you need to modify the configuration:

  1. Unload the current configuration: launchctl unload ~/Library/LaunchAgents/com.ollama.plist
  2. Make your changes to the plist file
  3. Reload the configuration: launchctl load ~/Library/LaunchAgents/com.ollama.plist
<!-- gh-comment-id:2585213086 --> @soakes commented on GitHub (Jan 11, 2025): Today while expermenting with my new Apple Silicon, I have ran into this exact same issue. I have tried various ways to resolve it and the best way I have found is to create a new `plist` file and not run the `brew services` version. This will then allow for upgrades not to interfear with Ollama and your ENV changes. Hope this helps people with the same issue. Below are taken from my notes: ## How to configure Ollama with Custom Environment Variables on macOS ## Overview This guide explains how to configure Ollama to listen on all network interfaces (0.0.0.0) on macOS by creating a custom launch agent configuration. This method ensures the configuration persists through Ollama updates, unlike using the default brew services approach. ## Prerequisites - Ollama installed via Homebrew - Administrative access to your macOS system ## Configuration Steps ### 1. Create Custom Launch Agent Configuration Create a new launch agent configuration file in your user's LaunchAgents directory: ```bash cat << 'EOF' > ~/Library/LaunchAgents/com.ollama.plist <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.ollama</string> <key>ProgramArguments</key> <array> <string>/opt/homebrew/bin/ollama</string> <string>serve</string> </array> <key>EnvironmentVariables</key> <dict> <key>OLLAMA_HOST</key> <string>0.0.0.0</string> </dict> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> </dict> </plist> EOF ``` ### 2. Load the Launch Agent After creating the configuration file, load it using launchctl: ```bash launchctl load ~/Library/LaunchAgents/com.ollama.plist ``` ## Configuration Breakdown The launch agent configuration includes several important components: - `Label`: Unique identifier for the launch agent - `ProgramArguments`: Specifies the Ollama executable path and the 'serve' command - `EnvironmentVariables`: Sets OLLAMA_HOST to '0.0.0.0' to listen on all interfaces - `RunAtLoad`: Ensures the service starts automatically at login - `KeepAlive`: Keeps the service running continuously ## Notes - No system reboot is required after loading the configuration - This configuration will persist through Ollama updates - The service will automatically start when you log in ## Troubleshooting If you need to modify the configuration: 1. Unload the current configuration: `launchctl unload ~/Library/LaunchAgents/com.ollama.plist` 2. Make your changes to the plist file 3. Reload the configuration: `launchctl load ~/Library/LaunchAgents/com.ollama.plist`
Author
Owner

@fffx commented on GitHub (Mar 29, 2025):

Launchctl setenv doesn't work for me (homebrew service), by checking the "$HOMEBREW_PREFIX/var/log/ollama.log", I noticed the env variable OLLAMA_ORIGINS I wanted to change is not affected, I ended up with updating the plist file.

diff -u   /opt/homebrew/opt/ollama/homebrew.mxcl.ollama.plist /opt/homebrew/opt/ollama/homebrew.mxcl.ollama.plist.bak
--- /opt/homebrew/opt/ollama/homebrew.mxcl.ollama.plist 2025-03-29 23:55:46
+++ /opt/homebrew/opt/ollama/homebrew.mxcl.ollama.plist.bak      2025-03-29 23:56:47
@@ -27,10 +27,5 @@
   <string>/opt/homebrew/var/log/ollama.log</string>
   <key>WorkingDirectory</key>
   <string>/opt/homebrew/var</string>
-  <key>EnvironmentVariables</key>
-  <dict>
-    <key>OLLAMA_ORIGINS</key>
-    <string>*</string>
-  </dict>
 </dict>
 </plist>


And then

brew services restart ollama
<!-- gh-comment-id:2764257743 --> @fffx commented on GitHub (Mar 29, 2025): Launchctl setenv doesn't work for me (homebrew service), by checking the "$HOMEBREW_PREFIX/var/log/ollama.log", I noticed the env variable `OLLAMA_ORIGINS` I wanted to change is not affected, I ended up with updating the plist file. ``` diff -u /opt/homebrew/opt/ollama/homebrew.mxcl.ollama.plist /opt/homebrew/opt/ollama/homebrew.mxcl.ollama.plist.bak --- /opt/homebrew/opt/ollama/homebrew.mxcl.ollama.plist 2025-03-29 23:55:46 +++ /opt/homebrew/opt/ollama/homebrew.mxcl.ollama.plist.bak 2025-03-29 23:56:47 @@ -27,10 +27,5 @@ <string>/opt/homebrew/var/log/ollama.log</string> <key>WorkingDirectory</key> <string>/opt/homebrew/var</string> - <key>EnvironmentVariables</key> - <dict> - <key>OLLAMA_ORIGINS</key> - <string>*</string> - </dict> </dict> </plist> ``` And then ``` brew services restart ollama ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#47324