Environment variables in Mac OS X

后端 未结 9 1506
萌比男神i
萌比男神i 2020-11-22 14:57

Update: The link below does not have a complete answer. Having to set the path or variable in two places (one for GUI and one for shell) is lame.

No

相关标签:
9条回答
  • 2020-11-22 15:03

    I think what the OP is looking for is a simple, windows-like solution.

    here ya go:

    https://www.macupdate.com/app/mac/14617/rcenvironment

    0 讨论(0)
  • 2020-11-22 15:03

    You can read up on linux, which is pretty close to what Mac OS X is. Or you can read up on BSD Unix, which is a little closer. For the most part, the differences between Linux and BSD don't amount to much.

    /etc/profile are system environment variables.

    ~/.profile are user-specific environment variables.

    "where should I set my JAVA_HOME variable?"

    • Do you have multiple users? Do they care? Would you mess some other user up by changing a /etc/profile?

    Generally, I prefer not to mess with system-wide settings even though I'm the only user. I prefer to edit my local settings.

    0 讨论(0)
  • 2020-11-22 15:05

    For GUI apps, you'll have to create and edit ~/.MacOSX/environment.plist. More details here. You will need to log out for these to take effect. I'm not sure if they also affect applications launched from Terminal, but I assume they would.

    For apps launched from Terminal, you can also edit the ~/.profile file.

    0 讨论(0)
  • 2020-11-22 15:06

    If you want to change environment variables permanently on macOS, set them in /etc/paths. Note, this file is read-only by default, so you'll have to chmod for write permissions.

    0 讨论(0)
  • 2020-11-22 15:07

    There's no need for duplication. You can set environment variables used by launchd (and child processes, i.e. anything you start from Spotlight) using launchctl setenv.

    For example, if you want to mirror your current path in launchd after setting it up in .bashrc or wherever:

    PATH=whatever:you:want
    launchctl setenv PATH $PATH
    

    Environment variables are not automatically updated in running applications. You will need to relaunch applications to get the updated environment variables (although you can just set variables in your shell, e.g. PATH=whatever:you:want; there's no need to relaunch the terminal).

    0 讨论(0)
  • 2020-11-22 15:07

    Just open the ~/.profile file, via nano in Terminal and type there :

    export PATH=whatever/you/want:$PATH
    

    Save this file (cmd+X and Y). After that please logout/login again or just open a new tab in Terminal and try use your new variable.

    PLEASE DON'T forget to add ":$PATH" after whatever/you/want, otherwise you'll erase all paths in PATH variable, which were there before that.

    0 讨论(0)
提交回复
热议问题