Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac 端环境变量配置 #47

Open
pfan123 opened this issue Sep 23, 2019 · 0 comments
Open

Mac 端环境变量配置 #47

pfan123 opened this issue Sep 23, 2019 · 0 comments

Comments

@pfan123
Copy link
Owner

pfan123 commented Sep 23, 2019

Mac 使用 bash 做为默认的 shell,MAC OS 环境配置文件如下:

# 系统级别
/etc/profile
/etc/paths 
/etc/bashrc

# 用户级别
~/.bash_profile 
~/.bash_login 
~/.profile 

~/.bashrc

前三个是系统级别的环境变量针对所有用户,后面四个带有 ~/ 用户级别的环境变量。

  • 前三个系统级别环境配置会在系统启动时加载。
  • ~/.bash_profile~/.bash_login~/.profile 依次加载,若 ~/.bash_profile 不存在,依次加载后面几个文件;若 ~/.bash_profile 文件存在,后面几个文件不会加载
  • ~/.bashrc 在 bash shell 打开时加载

全局环境变量设置

修改全局环境变量时候参考系统默认的环境变量配置格式。

修改全局环境变量需要 root 权限。

  • /etc/paths 全局建议修改这个文件
  • /etc/profile 不建议修改这个文件,全局共有配置,用户登录时候都会加载该文件
  • /etc/bashrc 一般在这个文件中添加系统级别的环境变量,全局共有配置,bash shell 执行时候都会加载

用户级别环境变量设置

~/.bash_profile 中配置环境,格式如下:

# 使用冒号隔开 export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
export PATH=$PATH:<PATH 1>:<PATH 2>:<PATH 3>:------:<PATH N> 

# 或者 
export PATH=${PATH}:<PATH 1>
export PATH=${PATH}:<PATH 2>

# 第一种将路径合并在一起,不方便删除,建议使用第二种,换行挨个设置

查看 PATH

echo $PATH

命令行添加 PATH

# 覆盖是添加
echo 'export PATH=$HOME/openwhisk/bin:$PATH' > "$HOME/.bash_profile" 

# 增量式添加
echo 'eval "$(register-python-argcomplete wskadmin)"' >> "$HOME/.bash_profile"
echo 'export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig'>> "$HOME/.bash_profile"

重新载入配置文件

在环境配置完毕后,重载入配置文件生效,执行以下指令:

source <相应文件配置文件>

#示例
source .bash_profile

Other Resources

Mac 每次都要执行source ~/.bash_profile 配置的环境变量才生效

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant