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

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

  1. Restart Obsidian to ensure it picks up the changes.
  2. Open the Obsidian Terminal.
  3. Verify that the PATH is correct by running:
    echo $PATH
    
    You should see /opt/homebrew/bin in the output.
  4. Test a command:
    which gemini
    # Or
    gemini --help
    
    It should now work as expected.

3. Troubleshooting

Why does this happen?

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.