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

相关推荐
无意feel14 小时前
MacOS 安装neofetch cmatrix lolcat
macos·数字雨·彩虹特效
KevinShi_BJ16 小时前
MacOS 上安装 Docker 和启动 LangBot
macos
ricky_fan18 小时前
(25年12月)claude code报错:might not be available in your country
macos·bash
james bid18 小时前
MacBook Pro 2015 上 XUbuntu 24.04 启用 eGPU (GeForce GTX 1080 Ti) 和核显黑屏问题解决
linux·ubuntu·macos·cuda·egpu
私人珍藏库19 小时前
[Mac] Mac风扇控制软件 iFan V1.1.1
macos
腾讯云qcloud075519 小时前
腾讯位置商业授权iOS 轨迹SDK
macos·ios·cocoa
新手村领路人19 小时前
MacOS Tahoe26.1自制定时休眠app
macos
2501_9160074719 小时前
没有 Mac,如何在 Windows 上架 iOS 应用?一套可落地的工程方案
android·macos·ios·小程序·uni-app·iphone·webview
乐之者v2 天前
mac操作快捷键命令
macos
一步徐龙的浪2 天前
Scholaread Mac版更新后无法用手机验证码登录
macos·scholaread·靠岸学术