Moving the .ollama Directory to an External Drive for Ollama Model Management
When working with large language models like .ollama
, you might find that these files take up a significant amount of space on your Mac’s internal storage. This tutorial will guide you through moving the .ollama
directory to an external drive, enabling you to free up space and easily transfer your work between different computers. This guide is designed for users with limited knowledge of the terminal and aims to ensure data safety throughout the process.
Prerequisites
- An external drive connected to your Mac.
- Basic familiarity with navigating Finder.
Step 1: Locate Your .ollama
Directory
The .ollama
directory might be hidden since it starts with a dot. To view hidden files in Finder:
- Open Finder.
- Navigate to your home directory (usually your username).
- Press
Command
+Shift
+.
(period key) to toggle the visibility of hidden files.
Your .ollama
directory should now be visible if it exists.
Step 2: Find the Path to Your .ollama
Directory and External Drive
Before moving the .ollama
directory, we need to know its current location and where you want to move it on your external drive.
- Open
Terminal
(you can find it using Spotlight withCommand
+Space
and typing “Terminal”). - Type
cd
(note the space aftercd
), then drag and drop your.ollama
directory from Finder into the Terminal window. PressEnter
. This changes your current directory to.ollama
. - Type
pwd
and pressEnter
. This command prints the path to your current directory. It should look something like
. Note this path./Users/yourusername/.ollama
- To find the path to your external drive, type
and presscd /Volumes/
Enter
, then typels
and pressEnter
to list all connected drives. Identify your external drive from the list.
Step 3: Backup Your .ollama
Directory
Before making any changes, let’s create a backup of your .ollama
directory on your external drive. Replace YourExternalDrive
with the name of your external drive.
rsync -avh --progress /Users/yourusername/.ollama /Volumes/YourExternalDrive/.ollama_backup
Warning: Ensure you have the correct paths to avoid data loss.
Step 4: Move the .ollama
Directory
Now, we will use rsync
to safely move the .ollama
directory to your external drive. This method allows for resuming if the transfer is interrupted and provides progress updates.
Replace YourExternalDrive
with your drive’s name:
rsync -avh --progress /Users/yourusername/.ollama /Volumes/YourExternalDrive/.ollama
Step 5: Verify the Transfer
To ensure all files have been successfully transferred, you can compare the original and new directories:
diff -rq /Users/yourusername/.ollama /Volumes/YourExternalDrive/.ollama
No output means the transfer was successful.
Step 6: Remove the Original .ollama
Directory
After verifying the transfer, delete the original directory to free up space:
rm -rf /Users/yourusername/.ollama
Warning: Double-check the path before executing to avoid accidental data loss.
Step 7: Create a Symbolic Link
To maintain access to .ollama
as if it were still in its original location, we’ll create a symlink:
ln -s /Volumes/YourExternalDrive/.ollama /Users/yourusername/.ollama
Step 8: Test the Symlink
Ensure the symlink points to the new location correctly:
ls -l /Users/yourusername/.ollama
The output should indicate that it’s linked to your external drive.
ls -l /Users/yourusername/.ollama
ls -l $HOME/.ollama
Launch Ollama by navigating to your Applications folder and opening Ollama, or from the terminal with:
<code>ls -l $HOME/.ollama</code>
ls -l /Users/yourusername/.ollama
Conclusion
You’ve successfully moved your .ollama
directory to an external drive and created a symlink for seamless access. This setup allows you to manage large files efficiently and transfer your work between computers easily. Remember to handle terminal commands with care, especially when moving or deleting files, to avoid data loss.