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.重启试试

相关推荐
A懿轩A4 小时前
Claude Code 2026 最新版下载安装教程详细版 涵盖Windows 和 MacOS 安装 附常见问题解决方案
windows·macos
倔强的石头1065 小时前
SenseNova-U1 实战体验:从网页版生成,到 Mac 踩坑,再到 CUDA 服务器跑通本地部署
运维·服务器·macos
zandy10111 天前
2026 主流技术栈:hermes agent多环境安装配置:Windows/Mac/Linux
linux·windows·macos
2501_916008891 天前
Mac 上生成 AppStoreInfo.plist 文件,App Store 上架
android·macos·ios·小程序·uni-app·iphone·webview
猫头虎1 天前
【Trea】Trea国内版|国际版|海外版下载|Mac版|Windows版|Linux下载配置教程
linux·人工智能·windows·macos·aigc·ai编程·agi
大可ai中文版镜像1 天前
OpenAI Codex Desktop App 保姆级安装教程(Windows / Mac)
人工智能·macos·codex
文滨1 天前
10分钟搞定!Mac 配置 GitHub SSH 完全指南(小白也能看懂)
前端·macos·ssh·github
明月(Alioo)1 天前
macOS 上 Charles 代理 HTTPS 抓包失败问题完整解决方案
网络协议·macos·https
Rudon滨海渔村1 天前
Mac录屏教程:只需要内录电脑声音,不需要麦克风声音
macos·免费·录屏·blackhole
00后程序员张2 天前
Windows 下怎么生成 AppStoreInfo.plist?不依赖 Xcode 的方法
ide·macos·ios·小程序·uni-app·iphone·xcode