Where Does Ollama Store Models? A Simple Guide to Customizing the Storage Location and Freeing Up Your C Drive! (Win/Linux/macOS)
Enjoying Ollama is great, but downloading models one after another, often several gigabytes in size, can be frustrating when your C drive space becomes scarce, right? By default, Ollama tends to store all its treasures (i.e., the downloaded models) on your C drive (or your home directory), which can be a "sweet burden" for your system disk.
Don't worry! This guide is your "C Drive Rescue Manual." We'll walk you through how to find a spacious new home for Ollama's models on the three major operating systems: Windows, Linux, and macOS, completely eliminating the problem of insufficient space!
Why bother with this? There are many benefits:
- Free Up C Drive Space: Moving several GB or even tens of GB of data away can relieve the burden on your system disk.
- Smoother Computer Performance: With sufficient space on your C drive, the system runs more smoothly.
- Clearer Model Management: Having all models neatly organized in one place makes it easier to find and back them up.
Before you start, let's do some preparation:
- Choose a "New Home" Address: Find a hard drive partition with enough space (such as D drive, E drive, or another mount point on Linux/macOS).
- Create a Dedicated Folder: In the chosen location, create a folder specifically for Ollama models. For example:
- Windows:
D:\OllamaModels
orE:\ai_models\ollama
- Linux/macOS:
/data/OllamaModels
or/home/your_username/ollama_files
- Super Important Tip: It's best to use a path that contains only English characters and no spaces; otherwise, you might encounter strange problems!
- Windows:
Ready? Let's see how to do it on different systems!
Finding a New Home for Models: Windows Edition 🏡
Windows users, look here! Ollama stores models in C:\Users\<your_username>\.ollama\models
by default. We have three ways to relocate them:
Method 1: Once and For All - Get it Right During Initial Installation (Suitable for Fresh Installations)
If you haven't installed Ollama yet or plan to reinstall it, this is the easiest way!
Download the Installation Package: Download
OllamaSetup.exe
from the Ollama official website.Install via Command Line: Open your Command Prompt (CMD) or PowerShell, use the
cd
command to navigate to the folder where the installation package is located. Then, execute the following command (remember to replace the path with your own!):powershell.\OllamaSetup.exe /DIR="D:\OllamaModels"
Here,
/DIR=
tells the installer: "Install the files toD:\OllamaModels
!"Follow the Installation Prompts: Next, follow the installation wizard. After installation, Ollama will obediently download the models to the location you specified.
Method 2: Highly Recommended - Modify Environment Variables for Flexibility and Long-Term Effect (Suitable for Existing Users)
This is the most popular and flexible method. By setting an "environment variable," you tell Ollama where new models should be stored.
Find the "Environment Variables" Settings:
- The quickest way: Press the
Win
key, search for "environment variables" directly, and select "Edit the system environment variables." - In the "System Properties" window that opens, click the "Environment Variables(N)..." button in the lower right corner.
- The quickest way: Press the
Create a New "System Variable":
- In the "System variables(S)" area below, click "New(W)...".
- Variable name: Fill in
OLLAMA_MODELS
(case is usually not sensitive, but uppercase is recommended). - Variable value: Fill in the path to your prepared new home, such as
D:\OllamaModels
. - Click "OK" to save this new variable. Then click "OK" all the way to close all settings windows.
Restart the Ollama Service:
- Find the Ollama icon in the lower right corner of the taskbar, right-click it, and select "Quit Ollama" to exit.
- Then restart Ollama (e.g., find it in the Start menu and run it again).
- Why restart? To allow Ollama to read the new "road sign" (environment variable) you just set.
What is an "Environment Variable"? Simply put, it's like a global "sticky note" in the computer system. Many programs (including Ollama) will look at these "notes" to decide how to work, such as where to store files.
OLLAMA_MODELS
is a "sticky note" dedicated to Ollama, telling it where the model repository is.
Method 3: The Great Shift - Migrate Existing Models (Suitable for Moving Existing Models)
If you have already downloaded a lot of models and want to move them, use this method.
- Stop Ollama First:
- Open Command Prompt (CMD) or PowerShell.
- Completely close the Ollama process (just exiting the taskbar icon may not be enough):powershell
taskkill /F /IM ollama.exe /T
/F
means force close,/IM
specifies the program name,/T
tries to close child processes. A successful prompt is good.
- Move!
- Open File Explorer and find Ollama's old home:
C:\Users\<your_username>\.ollama\models
. - Copy or cut this entire
models
folder to your prepared new address, such asD:\OllamaModels
. - Safety First: Before operating, it is recommended to back up the entire
C:\Users\<your_username>\.ollama
folder, just in case.
- Open File Explorer and find Ollama's old home:
- Tell Ollama the New Address: Follow the steps in Method 2 to set the
OLLAMA_MODELS
environment variable so that its value points to your new folder path (e.g.,D:\OllamaModels
). - Restart Ollama.
- Check: Open the command line and run
ollama list
. If you can see the list of models you downloaded before, it means the move was successful!
Linux Friends, Look Here 🐧
On Linux systems, Ollama usually stores models in .ollama/models
under the user's home directory, which is ~/.ollama/models
.
Method 1: Prevention is Better Than Cure - Set the Path Before Installation (Suitable for Fresh Installations)
If you are installing via script or package manager, you can specify it before installation.
- Set the Environment Variable: Open your terminal and enter (remember to change it to your path):bashThe environment variable set by this
export OLLAMA_MODELS="/data/OllamaModels"
export
command is only valid in the current terminal session. - Execute the Installation Command: In the same terminal window, run your Ollama installation command (e.g.,
curl ... | sh
). This way, the installer can readOLLAMA_MODELS
and put the models in the location you specified.
Method 2: Once and For All - Modify the Configuration File (Recommended) (Suitable for Existing Users)
Want to make the setting permanent? Then write it into your shell configuration file.
- Edit the Configuration File:
- Open the terminal. Depending on what shell you are using, edit the corresponding file. Commonly used ones are bash (
~/.bashrc
) or zsh (~/.zshrc
). Open it with your favorite editor, for example:bashnano ~/.bashrc # Or nano ~/.zshrc
- At the end of the file, add a line (remember to change it to your path):bash
export OLLAMA_MODELS="/data/OllamaModels"
- Save the file and exit (in nano it's
Ctrl+X
, then pressY
, then press Enter).
- Open the terminal. Depending on what shell you are using, edit the corresponding file. Commonly used ones are bash (
- Make the Configuration Take Effect Immediately:
- Run:bash
source ~/.bashrc # Or source ~/.zshrc
- Alternatively, simply close the current terminal and reopen a new terminal window.
- Run:
- Restart the Ollama Service:
- If Ollama is running in the background (e.g., started with
ollama serve
or configured as a systemd service), you need to restart it. An easy way is to firstollama quit
(if you have that command), or find the process and kill it, and then restart the service. If it is a systemd service, it might be a command likesudo systemctl restart ollama
.
- If Ollama is running in the background (e.g., started with
Method 3: Model Relocation - Migrate Existing Models
The steps are similar to Windows:
- Make sure Ollama is stopped. (You can use
ps aux | grep ollama
to find the process, thenkill <pid>
) - Move the Folder:bashReminder Again: Backing up
# First make sure the target directory exists mkdir -p /data/OllamaModels # Move the contents of the old folder to the new home mv ~/.ollama/models/* /data/OllamaModels/ # You can choose to delete the old empty models directory (or keep it first to confirm that there are no problems) # rm -rf ~/.ollama/models
~/.ollama
before operating is always a good habit! - Set the Environment Variable: According to Method 2, make sure
OLLAMA_MODELS
points to your new path/data/OllamaModels
and make the configuration take effect. - Restart the Ollama Service.
- Verify: Run
ollama list
to see if the models are still there.
macOS Friends, Come Here
On macOS, the default path is also ~/.ollama/models
. The modification method is very similar to Linux, mainly through environment variables.
Method 1: Temporary Change - Valid for the Current Session
If you just want to temporarily change the location for downloading models, you can use launchctl
.
- Open Terminal.
- Run (replace the path with yours):bashThis setting is only valid for Ollama applications started from this terminal (or applications started later that need to read this environment variable). It will be lost after restarting the computer.
launchctl setenv OLLAMA_MODELS "/Volumes/ExternalDrive/OllamaModels"
- You can use
launchctl getenv OLLAMA_MODELS
to view the current settings. - Want to cancel?
launchctl unsetenv OLLAMA_MODELS
.
Method 2: Permanent Effect - Modify the Shell Configuration File (Recommended)
As with Linux, it is recommended to modify your shell configuration file. macOS uses zsh by default, so it's usually editing ~/.zshrc
.
- Edit the Configuration File: Open the terminal and run:bash
nano ~/.zshrc
- Add the Environment Variable: Add the following at the end of the file (replace the path with yours):bash
export OLLAMA_MODELS="/Users/your_username/Documents/OllamaModels"
- Save and Apply: Save and exit (Ctrl+X, Y, Enter), then run:bashOr just restart the terminal.
source ~/.zshrc
- Restart the Ollama Application: Make sure to quit the Ollama application (Quit from the menu bar icon), and then reopen it to load the new environment variable.
Method 3: Model Relocation - Migrate Existing Models
The steps are exactly the same as Linux:
- Quit the Ollama Application.
- Move the Folder: Use Finder or the
mv
command to move the contents of~/.ollama/models
to the new home.bashBackup first!mkdir -p "/Users/your_username/Documents/OllamaModels" mv ~/.ollama/models/* "/Users/your_username/Documents/OllamaModels/"
- Set the Environment Variable: Follow Method 2 to make sure
OLLAMA_MODELS
points to the new path, and make the configuration take effect. - Restart the Ollama Application.
- Verify: Run
ollama list
.
Alright! Now your Ollama models should be obediently staying in their new home, and your C drive can breathe a sigh of relief! Whether you are a user of any of these systems, I hope this guide can help you.