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

相关推荐
csdn_aspnet1 天前
macOS 10 、Docker 玩轉 MySQL
运维·mysql·macos·docker·容器·mac
秋雨梧桐叶落莳1 天前
【iOS】Block底层详解
macos·ios·cocoa
高调的涵涵3 天前
café 和 café 不是一个文件名
macos
独隅5 天前
WebStorm macOS 安装部署与高效调优完全指南
ide·macos·webstorm
独隅6 天前
WebStorm macOS 安装调优与实战效能全景
ide·macos·webstorm
2601_967987376 天前
安装 Redis 或 Redis Stack
linux·windows·redis·macos·安装
高调的涵涵6 天前
1GB 文件,df 说没占地方
macos
奶油话梅糖6 天前
苹果的内核跑上了安卓手机:2,631 Star 的 HakiOS 让 XNU 在 Adreno GPU 上画出 118 帧
android·macos·智能手机
独隅7 天前
WebStorm macOS 安装调优与实战效果全景
ide·macos·webstorm
木子欢儿7 天前
国内 macOS/Linux 安装 rust
linux·运维·服务器·macos·rust