-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contents: 设置环境变量配置源时是否应使用 .bashrc 而非 .bash_profile? #139
Comments
不过这点可能有争议,我看 golang.google.cn 和 goproxy.cn 上依然写的是把环境变量设置写到 .profile 中,但这样也会对 GUI 用户造成困扰 我还不确定 .bashrc 是否在所有主流发行版中都会被 .profile 调用,亦或者反过来,可能需要统计不同发行版的行为 另,rust 官方安装程序 rustup-init 中是这么写的 The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/home/user/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/home/user/.profile
/home/user/.bashrc 并列给出了 .profile 和 .bashrc |
> rg bash_profile
contents/rustup.mdx
37:echo 'export RUSTUP_UPDATE_ROOT={{http_protocol}}{{mirror}}/rustup' >> ~/.bash_profile
38:echo 'export RUSTUP_DIST_SERVER={{http_protocol}}{{mirror}}' >> ~/.bash_profile
contents/homebrew-bottles.mdx
28:echo 'export HOMEBREW_API_DOMAIN="{{http_protocol}}{{mirror}}/api"' >> ~/.bash_profile
29:echo 'export HOMEBREW_BOTTLE_DOMAIN="{{http_protocol}}{{mirror}}"' >> ~/.bash_profile
contents/homebrew.mdx
67: test -r ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
78: test -r ~/.bash_profile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile
155:test -r ~/.bash_profile && echo 'export HOMEBREW_BREW_GIT_REMOTE="{{http_protocol}}{{mirror}}/brew.git"' >> ~/.bash_profile # bash
156:test -r ~/.bash_profile && echo 'export HOMEBREW_CORE_GIT_REMOTE="{{http_protocol}}{{mirror}}/homebrew-core.git"' >> ~/.bash_profile
> rg bashrc
contents/julia.mdx
70:不同系统和命令行下永久设定环境变量的方式也不相同,例如 Linux Bash 下可以通过修改 `~/.bashrc` 文件实现该目的:
75:# ~/.bashrc
contents/git-repo.mdx
25:repo 的运行过程中会尝试访问官方的 git 源更新自己,如果想使用镜像源进行更新,可以将如下内容复制到你的`~/.bashrc`里
contents/flutter_infra.mdx
37:echo "export FLUTTER_STORAGE_BASE_URL=${FLUTTER_STORAGE_URL%/flutter_infra}" >> ~/.bashrc
contents/flutter.mdx
38:echo 'export FLUTTER_STORAGE_BASE_URL="{{http_protocol}}{{mirror}}"' >> ~/.bashrc
contents/dart-pub.mdx
29:echo 'export PUB_HOSTED_URL="{{http_protocol}}{{mirror}}"' >> ~/.bashrc
contents/rosdistro.mdx
29:# 为了持久化该设定,可以将其写入 .bashrc 中,例如
30:echo 'export ROSDISTRO_INDEX_URL={{http_protocol}}{{mirror}}/index-v4.yaml' >> ~/.bashrc 一个需要关注的问题是,似乎 macOS 的 bash 不会 source .bashrc(需要验证)。 |
根据目前的不完全统计 ~/.bash_profile 调用 ~/.bashrc 的发行版包括:
~/.bash_profile 和 ~/.bashrc 没有调用关系的发行版包括:
注:为简洁叙述起见, |
经验证,MacOS 14.1.2 (23B92),bash version 3.2.57(1)-release 可正常调用 ~/.bashrc |
不是这个意思。他应该是说 macOS 的 .profile 没有写去 source .bashrc,不是指 bash 启动时是否访问这个文件 (bash 启动时访问 profile 还是 rc 只看自己是不是 login shell) |
我刚才找人测试了 macOS 下打开图形界面的 terminal 时的情况,与 Linux 表现一致,即此时 zsh/bash 会把自己算作 non-login shell 因此 |
按照 brew 提供的 manpage:
emmm,我没有特别的偏好,只是看起来之前没有人考虑清楚这个问题。(至少 homebrew 看起来更倾向于在 macOS 上改 profile) |
@taoky “至少 homebrew 看起来更倾向于在 macOS 上改 profile”的问题在于,这样修改之后,在图形界面中打开 terminal (相信也是大多数 mac 用户最常用的办法)并不会加载 profile (根据我刚才的测试得出;这样也符合 shell 的设计逻辑,因为本来这种场景就不是 login shell),也就是相当于没设置。不知道问题出在哪里,可能是我的测试有误,需要扩大 macOS 样本数量。 |
今日阅读到了一段关于 .profile 与 .bashrc 的论述,供参考(来源):
|
这段话的作者认为环境变量应当在尽可能早的时候定义,并且 .profile 是合适的节点,我对此并不完全同意。
因此,作者为了希望实现所有交互进程能有共同的环境变量配置文件这一点,强行让 .profile 充当了这一角色,这更多体现的是作者本身的意志。 另一个角度,将环境变量配置工作从普通 shell 移动到 login shell 或者桌面系统这种父节点,也就意味着用户需要重新登录后才可使新的环境变量生效,为了追求形式上的优雅,要忍受不便利。就连 Windows 都提供了不注销刷新环境变量的 API,所以用户通过系统设置修改完环境变量或者用 Inno Setup 安装包安装完软件后 PATH 的更改会立刻通知到所有 Windows 进程,而无需重新登录或者重启。而非 Windows 用户更不会接受为了安装软件而重启/结束当前会话这种事情。 |
帮助页面的链接(Help page URL)
https://help.mirrorz.org/rustup/
原文 (Text)
若要长期启用镜像源,执行:
反馈和修正 (Feedback)
若要长期启用镜像源,执行:
备注 (Note)
.profile / .bash_profile 只有 interactive login shell (console 登录、SSH 登录)的情形会加载
.bashrc 只有 interactive non-login shell (GUI 启动 terminal、其他进程执行 bash)的情形会加载,但现代的发行版往往在 .profile 中 source .bashrc (注:可能需要进一步调查)
因此,在这里使用 .bash_profile 会对 GUI 用户造成一定的使用上的困扰,结合发行版实际,拟改为 .bashrc
The text was updated successfully, but these errors were encountered: