What's the most efficient way to export the functions/aliases defined in my .zshrc to be used anywhere. For example in my .zshrc

_foo() {
echo "bar"

And then invoke _foo in any script.

  • 2
    does zsh follow the convention bash uses, whereby you could have a global rc file such as /etc/zshrc?
    – DopeGhoti
    Mar 3, 2021 at 14:40
  • 1
    That or you could setup a script in /etc/profile.d that should be sourced no matter what shell you run.
    – Rob
    Mar 3, 2021 at 15:50
  • 1
    The table of zsh dotfiles at this link may help: scriptingosx.com/2019/06/…. It looks like /etc/zshenv may be what you're looking for.
    – Gairfowl
    Mar 4, 2021 at 10:37

1 Answer 1


As suggested in one of the comments, you could put them in the file /etc/zshenv. However, on many distributions, this file is supplied by the OS. Besides that, /etc/zshenv is sourced every time your system runs a Zsh script, even when it's not from an interactive shell. Putting too many customizations in /etc/zshenv has the potential to significantly slow down your system or even break things.

Instead, if your custom functions and aliases are meant for interactive usage only, it is generally wiser to put them into /etc/zshrc, which is sourced only for interactive shells.

Documentation: http://zsh.sourceforge.net/Doc/Release/Files.html#Startup_002fShutdown-Files

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .