赶知识网

Mac 环境变量配置

2023-04-11 / 484次点击 OS/操作系统

mac一般使用bash作为默认shell,如果安装了oh my sh,则默认使用zshshell。


Mac系统环境变量的加载顺序:


/etc/profile


/etc/paths


~/.bash_profile


~/.bash_login


~/.profile


~/.bashrc


/etc/profile和/etc/paths是系统级别的,全局配置(建议不修改),后面几个是当前用户级的环境变量。


如果~/.bash_profile存在,后面几个文件就会忽略不读,不存在时,才会以此类推读取后面的文件。


~/.bashrc没有上述规则,他始终加载,他是在bash shell打开的时候载入的。


修改.bash_profile

vi ~/.bash_profile


添加对应环境变量,如


export ANDROID_HOME=/Users/shaoc/Library/Android/sdk


一般重启shell设置就会生效,如果想立刻生效,则可执行下面的语句:


source ~/.bash_profile


.bash_login .profile .bashrc同上


在安装了oh my zsh后, .bash_profile 文件中的环境变量就无法起到作用,因为终端默认启动的是zsh,而不是bash shell,所以无法加载,需在~/.zshrc,增加source ~/.bash_profile


打开~/.zshrc 


vi ~/.zshrc 


按i键进入编辑状态,在文件末尾增加 


source ~/.bash_profile


, 然后按esc按键退出编辑,按


:wq


保存并退出



有用 没用

Top10

沪ICP备09053415号 © 赶知识网