Ollama is a powerful tool for working with AI models, but its default storage location on macOS can quickly fill up your internal drive. If you're working with large models or have limited disk space, it's essential to change the Ollama storage location to an external drive.
If you're searching for a way to change the Ollama storage location on your Mac, you're likely to find a plethora of incomplete and misleading instructions scattered across the web. A quick Google search will yield a dozen or so results, each promising to provide a straightforward solution to this seemingly simple problem. However, as you delve deeper into these guides, you'll quickly realize that they're nothing more than half-baked gloss-overs, lacking the crucial details and nuance necessary to successfully navigate the process.
You may find blog posts that briefly mention the importance of setting the OLLAMA_MODELS environment variable, only to leave you hanging without explaining how to actually do it. Others will provide vague instructions on moving files to an external drive, without specifying which files to move or where to put them. Some might even point you in the direction of editing configuration files, but fail to provide the necessary context or warnings about potential pitfalls.
As a result, many users are left frustrated and stranded mid-journey, unsure of how to proceed or troubleshoot the inevitable errors that arise. The lack of clear, step-by-step instructions has become a significant obstacle for those seeking to free up valuable disk space on their internal drive or simply manage their Ollama models more efficiently.
It was this very experience of wading through incomplete and misleading guides that compelled me to write this comprehensive tutorial. My goal is to provide a detailed, easy-to-follow guide that will walk you through the entire process of changing the Ollama storage location on macOS, from start to finish. By following these steps, you'll be able to successfully move your Ollama models and data to an external drive, ensuring that you can continue to work with your AI projects without running out of storage space or encountering unnecessary headaches.
This guide will walk you through the step-by-step process of moving Ollama's models and data to an external drive, ensuring that you can continue to work with your AI projects without running out of storage space.
You can change the directory where Ollama stores its models and other files on macOS by setting the OLLAMA_MODELS
environment variable. This variable tells Ollama where to look for and store its data.
Here's a step-by-step guide to move the storage to an external drive:
-
Identify Your External Drive Path:
- Plug in your external drive.
- Open Finder.
- Your external drive will appear in the sidebar under "Locations". Click on it.
- Create a new folder on the drive where you want Ollama to store its files (e.g.,
ollama_files
). - To get the full path:
- Right-click (or Control-click) on the new folder you created.
- Hold down the Option (⌥) key on your keyboard.
- Select "Copy 'folder_name' as Pathname".
- This will copy the full path to your clipboard (e.g.,
/Volumes/MyExternalDrive/ollama_files
). Let's call thisyour_new_path
.
-
Quit Ollama Completely:
- If the Ollama application is running (you see the Llama icon in the menu bar), click on it and select "Quit Ollama".
- If you run Ollama from the terminal (e.g., using
ollama serve
), make sure that process is stopped (usually Ctrl+C in the terminal where it's running). - It's also a good idea to ensure the background service is stopped while you make changes. Open Terminal (Applications > Utilities > Terminal) and run:
Note: If you installed Ollama differently, the service name might vary, butlaunchctl unload ~/Library/LaunchAgents/com.ollama.ollama.plist # You might see "Unload failed: 5: Input/output error" if it wasn't running, which is okay. # Also try stopping it directly if the above gives errors or doesn't work launchctl stop com.ollama.ollama
com.ollama.ollama
is the standard for the macOS app.
-
Move Existing Ollama Data (Optional but Recommended):
- Ollama's default storage location on Mac is
~/.ollama/models
. The~
symbol represents your home directory (/Users/your_username
). - Open Finder, press
Shift + Command + G
, type~/.ollama
and press Enter. - You'll see a
models
folder inside. - Copy the entire contents of this
models
folder to the new directory you created on your external drive (your_new_path
). It's safer to copy first, then delete the original later once you confirm it's working.
- Ollama's default storage location on Mac is
-
Set the
OLLAMA_MODELS
Environment Variable Persistently: This is the crucial step. You need to make sure the Ollama process (whether started by the app or terminal) sees this variable before it starts. Here are the two main methods for macOS:-
Method 1: Using
launchctl setenv
(Easier, applies to GUI apps and services launched by user)- Open Terminal.
- Run the following command, replacing
/Volumes/MyExternalDrive/ollama_files
with the actual path you copied in Step 1:launchctl setenv OLLAMA_MODELS /Volumes/MyExternalDrive/ollama_files
- Important: This setting persists only until you log out or restart your Mac. To make it permanent across reboots, you need to add this command to your shell's startup file (like
~/.zshrc
or~/.bash_profile
).- Edit your shell profile:
nano ~/.zshrc
(or~/.bash_profile
if you use bash). - Add the line:
launchctl setenv OLLAMA_MODELS /Volumes/MyExternalDrive/ollama_files
- Save the file (Ctrl+O, Enter) and exit (Ctrl+X).
- This ensures the variable is set whenever you open a terminal, and
launchctl setenv
applies it to the broader user session environment.
- Edit your shell profile:
-
Method 2: Editing the Ollama LaunchAgent Plist (More Robust for the Background Service)
- This directly tells the
launchd
service (which manages the Ollama background process for the app) about the environment variable. - Open Terminal.
- Edit the Ollama plist file. You can use
nano
or a text editor:nano ~/Library/LaunchAgents/com.ollama.ollama.plist
- Find the
<dict>
section within the main<plist>
tags. Inside this<dict>
, add the followingEnvironmentVariables
section (if it doesn't exist) or add theOLLAMA_MODELS
key to it (if it does exist). Replace the path with your actual path:<key>EnvironmentVariables</key> <dict> <key>OLLAMA_MODELS</key> <string>/Volumes/MyExternalDrive/ollama_files</string> </dict>
- Make sure this new
<key>EnvironmentVariables</key>
and its associated<dict>
are at the same level as other keys likeLabel
,ProgramArguments
, etc., directly inside the main<dict>
. - Save the file (Ctrl+O, Enter) and exit (Ctrl+X).
- Crucially, reload the service definition:
launchctl unload ~/Library/LaunchAgents/com.ollama.ollama.plist launchctl load ~/Library/LaunchAgents/com.ollama.ollama.plist
- This directly tells the
-
-
Start Ollama:
- You can now start the Ollama application from your Applications folder, or run
ollama serve
orollama run some-model
in the terminal.
- You can now start the Ollama application from your Applications folder, or run
-
Verify the Change:
- Run a command like
ollama list
. It should show your models (if you moved them). - Try pulling a small new model:
ollama pull gemma:2b
. - Check your new directory on the external drive (
your_new_path
). You should see the files for the new model appear there, not in~/.ollama/models
.
- Run a command like
-
Clean Up (Optional):
- Once you are confident that Ollama is using the new directory on the external drive and your existing models are accessible, you can delete the original
models
folder inside~/.ollama
to free up space on your internal drive. rm -rf ~/.ollama/models
(Use with caution! Make sure you copied everything correctly).
- Once you are confident that Ollama is using the new directory on the external drive and your existing models are accessible, you can delete the original
Choose either Method 1 or Method 2 in Step 4. Method 2 is generally more reliable specifically for the background service managed by launchd
, which the Ollama macOS application uses. Method 1 is simpler to execute initially but requires the extra step for persistence across reboots.
In conclusion, changing the Ollama storage location on macOS is a straightforward process that requires setting the OLLAMA_MODELS environment variable along with some config & parameters, and moving the existing data to an external drive. By following these steps, you can free up valuable disk space on your internal drive and ensure that your AI projects continue to run smoothly. Remember to verify the changes by running a few commands and checking the new storage location to ensure that everything is working as expected. With this guide, you should be able to successfully move Ollama's storage location to an external drive and enjoy more flexibility and storage space for your AI projects.
Comments
Post a Comment
What do you think?