Setting environment variables on OS X

后端 未结 30 3167
你的背包
你的背包 2020-11-21 05:15

What is the proper way to modify environment variables like PATH in OS X?

I\'ve looked on Google a little bit and found three different files to edit:

30条回答
  •  渐次进展
    2020-11-21 06:02

    There are two type of shells at play here.

    • Non-login: .bashrc is reloaded every time you start a new copy of Bash
    • Login: The .profile is loaded only when you either login, or explicitly tell Bash to load it and use it as a login shell.

    It's important to understand here that with Bash, file .bashrc is only read by a shell that's both interactive and non-login, and you will find that people often load .bashrc in .bash_profile to overcome this limitation.

    Now that you have the basic understanding, let’s move on to how I would advice you to set it up.

    • .profile: create it non-existing. Put your PATH setup in there.
    • .bashrc: create if non-existing. Put all your aliases and custom methods in there.
    • .bash_profile: create if non-existing. Put the following in there.

    .bash_file:

    #!/bin/bash
    source ~/.profile # Get the PATH settings
    source ~/.bashrc  # Get Aliases and Functions
    #
    

提交回复
热议问题