Use Gemini with Obsidian
Using Gemini (and other tools) with the Obsidian Terminal
1. Goal
To make command-line tools installed with Homebrew (like gemini, brew, node, etc.) work correctly within the Obsidian Terminal plugin on macOS.
This is necessary because the Obsidian Terminal runs a "non-login" shell, which doesn't always load the system PATH where these tools are located.
2. Steps
Step 2.1: Update Shell Configuration Files
Open your standard macOS Terminal app and run the following commands. This ensures your PATH is correctly defined for both login and non-login shells.
echo 'export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:$PATH"' >> ~/.zprofile
Step 2.2: Link the Configuration Files
Add the following line to the end of your ~/.zshrc file. This forces non-login shells (like the one in Obsidian) to load the login shell's environment.
echo '[[ -f ~/.zprofile ]] && source ~/.zprofile' >> ~/.zshrc
Step 2.3: Apply Changes
Load the updated configurations in your open terminal.
source ~/.zshrc
source ~/.zprofile
Step 2.4: Verify in Obsidian
- Restart Obsidian to ensure it picks up the changes.
- Open the Obsidian Terminal.
- Verify that the
PATHis correct by running:
You should seeecho $PATH/opt/homebrew/binin the output. - Test a command:
It should now work as expected.which gemini # Or gemini --help
3. Troubleshooting
Why does this happen?
- Login Shells (e.g., standard Mac Terminal): When you open a new terminal window, it reads configuration from
~/.zprofile. This is where your HomebrewPATHwas likely set. - Non-Login Shells (e.g., Obsidian Terminal): These shells only read configuration from
~/.zshrc. They don't load~/.zprofileby default.
The fix works by making sure the PATH is defined in both files and that the non-login shell (.zshrc) is instructed to load the settings from the login shell (.zprofile).
Still not working?
If you're still having issues, the configuration files (~/.zprofile and ~/.zshrc) might have conflicting or incorrect settings. You can inspect them by running:
cat ~/.zprofile
cat ~/.zshrc
Look for any other lines that modify the PATH variable.