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

相关推荐
尽兴-4 小时前
macOS 系统下 Chrome 浏览器安装 HTTPS 证书完整指南
chrome·macos·https·证书·ssl·pem·crt
专注于大数据技术栈4 小时前
Mac本地安装python
macos
珊珊而川4 小时前
MAC-SQL:SQL-Llama 的具体训练流程
sql·macos·llama
2501_9151063217 小时前
App 怎么上架 iOS?从准备资料到开心上架(Appuploader)免 Mac 上传的完整实战流程指南
android·macos·ios·小程序·uni-app·iphone·webview
青木狐17 小时前
关闭 macOS 屏幕捕捉 在录制或截图时显示的「录制指示浮窗」。
macos·mac
LvLuffy1 天前
mac Android Studio配置adb环境(使用adb报错 adb: command not found)
macos·adb·android studio
库奇噜啦呼1 天前
【iOS】UICollectionView
macos·ios·cocoa
2501_915909061 天前
iOS 发布 App 全流程指南,从签名打包到开心上架(Appuploader)跨平台免 Mac 上传实战
android·macos·ios·小程序·uni-app·cocoa·iphone
私人珍藏库2 天前
Clip Studio Paint EX v2.0.6 For MacOS – 官方版本+逆向补丁下载,M4芯片Mac实机测试好用
macos
绝世唐门三哥2 天前
MacOS-Terminal直接command解压缩文件文件夹
macos·命令行·压缩