MacOS环境变量source生效但重启后又失效

.bash_profile 和 .zshrc 都是macos系统重环境变量配置的文件,但是两者有不同之处。

.bash_profile:在执行source ~/.bash_profile,只在当前窗口生效,但关闭当前终端窗口 或者 mac关机重启后不会再生效。

.zshrc:在执行source ~/.zshrc,这是永久生效的,mac每次启动会自动执行source ~/.zshrc,

两者都需要在操作完之后进行source保存操作才会让改变生效起作用。

现在macOS默认终端是zsh,执行的是/.zshrc文件,不会直接执行/.bash_profile文件,

所以一般会在~/.zshrc中添加source ~/.bash_profile,以确保.bash_profile中的修改永久生效。


查看当前系统使用的 shell(macos 自带 zsh)

可以在终端输入下面命令查看当前使用的 shell

bash 复制代码
echo $SHELL

结果会输出 /bin/zsh, 说明当前使用的是 zsh

查看 zsh 版本

bash 复制代码
zsh --version

在 zsh 中配置 .bash_profile

1.编辑 .zshrc 文件

bash 复制代码
vim ~/.zshrc

2.在末尾加入应用 .bash_profile 配置

bash 复制代码
source ~/.bash_profile

3.Shift+:,输入 :wq 进行保存退出

4.重启试试

相关推荐
寒水馨13 小时前
macOS下载、安装uv-0.12.0(附安装包uv-aarch64-apple-darwin.tar.gz)
python·macos·rust·项目管理·包管理器·astral·pip替代
寒水馨14 小时前
macOS下载、安装protobuf-v35.1(附安装包protoc-35.1-osx-universal_binary.zip)
macos·google·grpc·序列化·protobuf·protoc·数据交换
寒水馨14 小时前
macOS下载、安装ripgrep-15.2.0(附安装包ripgrep-15.2.0-aarch64-apple-darwin.tar.gz)
macos·正则表达式·rust·ripgrep·rg·命令行搜索·代码搜索
起司喵喵2 天前
Flutter-MacOS桌面OS系统|flutter.+window_manager客户端OS模板
flutter·macos·策略模式
代码对我眨眼睛2 天前
macOS Google Chrome 常用快捷键
前端·chrome·macos
啊真真真2 天前
macOS下libnfc ..写卡失败问题及解决方案
macos·策略模式
叶 落2 天前
Mac 通过 Miniconda 安装 Python
python·macos·conda·miniconda
it-电商达人2 天前
告别手动对齐!Mac播放器Popvee Player支持本地AI自动生成字幕
人工智能·macos
2501_916008892 天前
iOS IPA文件反编译与打包操作方法,拆包分析防护和加固打包
android·macos·ios·小程序·uni-app·cocoa·iphone
凯丨2 天前
2GB 内存跑 Gemma 4 26B 模型:TurboFieldfare Mac 本地部署实测(2026 最新)
macos