I am studying zsh on macOS and I find when adding software to $PATH
you are usually supposed to write them in .zshrc
(zsh). However, Visual Studio Code documentation suggests
To add VS Code to your path, to do so run the following commands:
cat << EOF >> ~/.zprofile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF
I find zprofile
set the environment for login shells while zshrc
sets the environment for interactive shells. However, I cannot really see differences between two methods on macOS terminal since each terminal tab is a login session on macOS by default.
Is there any reason why Visual Studio Code on macOS suggests add $PATH to zprofile
instead of zshrc
and what will be the good practice?
CodePudding user response:
If you read this and this answer as well as the man page (man zsh
under STARTUP/SHUTDOWN FILES
) you might come to the following conclusion:
You are using MacOS, therefore every zsh you open is a login shell, that way you made sure, that .zprofile
will always be read. So if you append your $PATH
in your .zprofile
and and use zsh as a non interactive-shell you will be able to access your appended $PATH
. This might happen in a script of if other programs try to use a program that you added to your $PATH
.
Now on the other hand if you added VSCode to your .zshrc
it will always be available in an interactive shell. Which mean if you use VSCode 'manually' you will always have it at your disposal in zsh. But other programs/scripts might not find it.