0

I am using zsh and I wanted to modify the $PATH variable permanently. I can't seem to find either .zshrc or .zsh_profile on my computer -- I tried searching in Finder with enabled hidden files.

I tried creating .zshrc in my home folder. Here is the full text of what I pasted there.

/Users/dnes/Library/Python/3.9/bin

I then made this file executable. Here is what I now see when opening Terminal:

Last login: Wed Sep 27 20:30:43 on ttys000
/Users/dnes/.zshrc:1: permission denied: /Users/dnes/Library/Python/3.9/bin
dnes@MacBook-Air-Denis ~ % 

I also tried echo $ZDOTDIR to see where the file is. But the command only produced a blank line. Meanwhile echo $PATH produces a normal string of few paths divided by : as one normally expects.

I know that for one Terminal session I can use export $PATH. How do I nowadays modify my $PATH variable permanently?

dnes
  • 99
  • Those files don't exist by default you have to actually create them yourself. – mmmmmm Sep 21 '23 at 19:20
  • @mmmmmm Thank you for your comment. I did try creating my own .zshrc and .zsh_profile in my home folder. My zsh doesn't seem to read those files, as the paths I specified do not appear in $PATH. – dnes Sep 23 '23 at 08:23
  • What exactly is in your .zshrc and what is the full path to it? – mmmmmm Sep 23 '23 at 12:19
  • @mmmmmm I have created .zshrc in the folder /Users/dnes/ and I have written "/Users/dnes/Library/Python/3.9/bin" there – dnes Sep 24 '23 at 10:01
  • Let us see the full text of the .zshrc and paste it in the question - your wording here suggests that what you have done will not work – mmmmmm Sep 24 '23 at 10:04
  • @mmmmmm done, would you please look at it? – dnes Sep 27 '23 at 14:36
  • You don't just put the path in the file it needs to be valid zsh syntax which you know how to do as you show how in the last paragraph of your question. Just put the whol export statement you typed in the Termial into .zshrc and read the zsh docs which explain all this https://zsh.sourceforge.io/ – mmmmmm Sep 27 '23 at 14:47
  • For editors etc I have just fully read the duplicate I suggested and in general the answer is OK but when I think of all the details (which don't really apply to the OP) it is a bit too bash specific and the path_helper is not quite correct so a better duplicate should be used. – mmmmmm Sep 27 '23 at 14:58
  • To be explicit, you could for example put this in your .zshrc file: export PATH=/Users/dnes/Library/Python/3.9/bin:$PATH. – John Palmieri Sep 27 '23 at 18:16
  • @mmmmmm oh my god, it finally works. Many many thanks – dnes Sep 27 '23 at 21:16

1 Answers1

-1

After some investigating I stumbled upon the folder /etc/paths.d/ with one file containing part of my $PATH variable.

I created another file in this folder, put my paths in it, and now everything works. Not sure if that's the intended way to do it though.

dnes
  • 99
  • 1
    These are for all users on the Mac and might get deleted when upgrade the OS. You should CREATE the files you mention in your question – mmmmmm Sep 21 '23 at 19:21
  • @mmmmmm They don't get deleted (I have files in there which date back to 2019), but not all users might have access to /Users/dnes/Library/Python/3.9/bin so user-specific paths could still cause issues. – nohillside Sep 27 '23 at 17:35