当我试图为节点设置最大内存时,它来了。有人告诉我要输入 ende_options = -max_old_space_size = 4096
在终端中,所有这些都可以解决。但是,当我关闭终端并再次打开终端时,环境选项就消失了。我必须再次输入它才能设置Env。
后来,我想知道我是否可以将该选项写入〜/.zshrc文件,我发现它对所有人都起作用。
因此,我在想这只是一个巧合,还是像./zshrc文件中的导出一样
It came to me when I was trying to set the max memory for Node. I was told to enter export NODE_OPTIONS=--max_old_space_size=4096
in the terminal, and it all worked out. However, when I close the terminal and open it again, the environment options was gone. I had to enter it again to set the env.
Later, I was wondering if I can write that option to ~/.zshrc file, and I found it worked once for all.
So, I was thinking if it is just a coincidence, or is it like export in the ./zshrc file a permanent version of export in command
发布评论
评论(2)
.zshrc
只是一个由每个交互式壳来源的文件,就像您已经在命令行中输入命令一样。但是,
.zprofile
文件是设置环境变量的更好选择。它仅通过登录外壳来源,但是任何非login Interactive shell都可能从最终从某些登录外壳继承其环境。.zshrc
is just a file that gets sourced by every interactive shell, exactly as if you had entered the commands on the command line.The
.zprofile
file, however, is a better choice for setting environment variables. It's sourced only by login shells, but any non-login interactive shell is likely to inherit its environment from, ultimately, some login shell.不要忘记
.zshrc
仅用于 Interactive 外壳。如果您还需要在非相互作用外壳中设置,则〜/.zshenv
将是一个更好的选择。无论哪种情况,您都必须意识到以下结果:
如果您在当前外壳中手动设置变量,目的是覆盖 在您的杂物中所做的设置,则创建一个子壳将再次还原来自点文件的设置,覆盖当前的设置。
如果您不喜欢这种效果,则可以在
〜/.zprofile
中设置值。这将仅在登录名(当然也继承给所有子过程)。只有当您创建一个新的登录-ZSH作为子壳时,此文件将再次采购并破坏您在调用Shell中进行的可能的手动更改。另一种可能性是使用,即
〜/.zshenv
,但仅在尚未有一个值时设置该值:即使它使用两行而不是仅使用一行,这也是我建议的方法,因为它允许您在需要时覆盖所有子壳的值,但仍然可以确保设置合适的默认值,如果没有进行覆盖。
Don't forget that
.zshrc
is only sourced for interactive shells. If you need the setting in non-interactive shells as well,~/.zshenv
would be a better choice.In either case, you have to aware of the following consequence:
If you manually set the variable in your current shell, with the purpose to override the settings done in your dotfile, creating a subshell will again restore the settings from the dotfile, overriding your current settings.
If you do not like this effect, you could set the value inside
~/.zprofile
. This will be executed only in a login-shell (and of course inherited to all child processes). Only if you create a new login-zsh as a subshell, this file will be sourced again and destroy possible manual changes which you have done in your calling shell.Another possibility would be to use, i.e.,
~/.zshenv
, but set the value only if it does not already have a value yet:Even though this uses two lines instead of only one, this is the approach I recommend, since it allows you to override the value for all subshells if needed, but still ensures that a suitable default is set, if no overriding took place.