I have OSX 10.8.2 with ZSH as my shell and iTerm as a terminal (don't know if the last thing is relevant). I have to mention that I'm relatively new to OSX.

I'm trying to set up some environment variables and I can't seem to figure out how.

I have two exports:

export GOBIN=$HOME/go/bin

I tried changing: .bashrc, .bash_profile, .profile, .zprofile, .zshrc, ~/.MacOSX/environment.plist. (The last one I modified with Property list editor from xcode).

I don't understand WHY is this not working. What's the proper way to do this?

  • 1
    Did you open a new shell after you made the changes? Those files are only read at shell startup. Feb 16 '13 at 20:44
  • New shell, restart, everything! Feb 16 '13 at 21:31
  • I'd try adding something like echo HI THERE to your .zshrc to verify it's being processed Feb 16 '13 at 21:39

OK, well, I can't answer right off the bat why it isn't working. You could give us some more detail. I also can't leave a comment due to lack of rep here (despite my rep on other stack exchange sites). So I'll at least try to make this an answer.

First of all, if you are in fact using zsh, ~/.profile, and all the bash rc files are irrelevant. Go ahead and focus on .zshrc. That will be the correct rc file the majority of the time for this kind of stuff.

This kind of stuff generally "just works", so I'm inclined to speculate there's some part of the process you're not understanding, or missing.

First of all, ensure you are, in fact, using zsh:

echo $SHELL
echo $0

Share this output, please.

Secondly, verify that things are, in fact, not working. You should have already posted the output of:

echo $PATH

Try this before and after running the export ... command. That's the only way to check that something else isn't going on.

A couple asides: restarts are irrelevant. If you put this stuff in your .zshrc, simply opening a new shell will suffice. Also, it might be easier to experiment by running these commands in an active shell, and not add them to your .zshrc file until you've resolved the issue.

Share the results of this and I'll get back to you.

  • I feel kind of sorry now that I see that I did something wrong, or forgot. I AM using zsh, but apparently the .zshrc was not saved properly when I left vim. Oopsie. Anyway, thanks! Feb 17 '13 at 20:31

That should work in ~/.zshenv or ~/.zshrc

If you have xcode you should also have dtrace which will let you see the files the system attempts to open as zsh executes which might help you track down what is happening

sudo dtrace -n 'syscall::open*:entry { printf("%s %s",execname,copyinstr(arg0)); }' -c zsh

Strangely I have a /etc/zshenv on my 10.7.5 but /etc/zshrc is what zsh attempts to load for the global config in that dtrace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.