Skip to main content

How to Externalize Ollama Storage Location on macOS: A Step-by-Step Guide

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.

Externalize Ollama Models

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.

Externalizing Ollama Model Storage

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:

  1. 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 this your_new_path.
  2. 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:
      launchctl 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
      
      Note: If you installed Ollama differently, the service name might vary, but com.ollama.ollama is the standard for the macOS app.
  3. 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.
  4. 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.
    • 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 following EnvironmentVariables section (if it doesn't exist) or add the OLLAMA_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 like Label, 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
        
  5. Start Ollama:

    • You can now start the Ollama application from your Applications folder, or run ollama serve or ollama run some-model in the terminal.
  6. 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.
  7. 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).

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

Popular posts from this blog

How to solve server authentication certificate failures on Microsoft RDP over SSL

Issue / Details User gets the following error when trying to get connected to a remote machine using .rdp file ERROR: The connection has been terminated because an unexpected server authentication certificate was received from the remote computer. Related Products Microsoft Remote Desktop, CyberArk - Privileged Access Manager (PAM, self-hosted); Privilege Cloud

Neon Desolation: A CyberPunk Short Story

In the city of Neo-Babylon, year 2073, rain seemingly never stopped. Metallic droplets clattered on chrome roofs, a ceaseless symphony of the future. Neon lights punctured the gloom, reflecting off slick streets and towering monoliths of steel and glass. Amid this panorama of progress, countless digital billboards flashed images of prosperity and satisfaction. But beneath the glossy surface, shadows crept. Our protagonist, Jack, was an echo runner. A professional data thief, wired to the teeth with the latest sub-dermal implants. He carried secrets from one end of the city to the other, an encrypted courier in an age where trust was as scarce as clean air.

High Valuations and Potential Corrections: Precautions for Global Investors in NYSE and NASDAQ

he New York Stock Exchange (NYSE) and NASDAQ are key investment hubs not only for American investors but also for those from Canada, Britain, Europe, and Australia. However, given the current economic signals—specifically the Buffett Indicator which suggests extreme overvaluation at a 193% ratio—investors worldwide should exercise caution. This gauge compares the total market capitalization of publicly traded stocks to the gross domestic product (GDP), and a reading near 200% indicates potential overvaluation which could lead to significant market corrections. Understanding the Current Market Environment The Buffett Indicator, a measure devised by Warren Buffett, assesses whether the stock market is fairly valued relative to the economic output. A ratio of 100% is seen as fair, but the current 193% suggests that the market is potentially overheated. This scenario resembles past conditions, like those in late 2021 when the...