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 小时前
nvm常用命令(nodejs)
macos·编辑器·nodejs·开发工具
小鸡脚来咯13 小时前
怎么配置主机名映射?
linux·windows·macos
牛奔15 小时前
macOS 使用 conda,同时本地安装了python,遇到 ModuleNotFoundError: No module named ‘xxx‘` 解决
开发语言·python·macos·conda
川川菜鸟16 小时前
Codex+ 中转 API 部署教程(Mac版)
macos
rockage17 小时前
【技巧】MacOS下使用LaunchDaemons实现开机自启动
macos
青花锁18 小时前
Mac电脑安装Docker
macos·docker·容器
李玮豪Jimmy2 天前
MacOS 上安装 JDK 并实现多版本灵活切换
macos
mixboot2 天前
VoxCPM 1.5.0 macOS
macos·voxcpm
甜可儿2 天前
mac环境安装不同版本maven
java·macos·maven
bl4ckpe4ch2 天前
从零开始Mac OS 开荒整理笔记
笔记·macos·开荒