安装程序如何在 Mac OSX 上设置 PATH 变量?

How does installers set PATH variable on Mac OSX?

我想知道 Mac Mac OSX 上的安装程序如何设置 PATH 变量。

例如:

查看 golang Mac OSX 安装程序。来自 link https://golang.org/doc/install:

Mac OS X package installer

Download the package file, open it, and follow the prompts to install the Go tools. The package installs the Go distribution to /usr/local/go.

The package should put the /usr/local/go/bin directory in your PATH environment variable. You may need to restart any open Terminal sessions for the change to take effect.

所以,我可以在 $PATH 中看到 /usr/local/go/bin,但它没有在 .profile、.bashrc 或 launchd.conf.

中设置

谁能帮我理解一下?

在 Mac OS X 中有几种设置环境变量的方法(lots of discussion here). In the case the Go package, it is adding a file in /etc/paths.d named go that contains /usr/local/go/bin. Here's an answer to another question explaining that a utility called path_helper is being launched 并且它正在检查 /etc/paths.d 目录。

您可以通过使用名为 Pacifist 的应用程序检查 Go 包的内容并查看它正在安装的文件来自行验证。