这里写目录标题
darwin__2">MacOS darwin 环境变量
List All Environment Variables
Use the printenv
command to display a list of currently set environment variables:
printenv
env_for_all_users_12">env for all users
What you (and anyone else finding this question) are almost certainly looking for is the following path:
/private/etc/paths
You can always put your edits into the /private/etc/paths.d
if you want to avoid changing the main system default “paths” configuration document, but then they will be appended to the end of your $PATH
variable, so if you want to add directories at the front of $PATH
(to override default system utilities, for example), you’ll just have to edit the main /private/etc/paths
file itself and add those to the top of the list. For example, I do this for a folder in which I store a handful of scripts I made myself, along with a few key utilities, such as mozjpeg
, that I want the system to always use instead of the defaults it comes with (that way all the jpeg files saved by pretty much any program get automatically compressed by up to 10 % more than the regular system cjpeg utility would compress them - I’ve read that the reason it isn’t default on most systems is because it’s much slower, but when you’re talking something like 0.14 seconds as opposed to 0.02 seconds, the “slower by a factor of 7” doesn’t really mean much of anything… assuming this is not a server, of course). I know plenty of people will probably warn about the potential “danger” of making edits this deeply in the system, but I’d say that if you’re looking for an answer like this, you probably know enough to deal with any utility naming conflicts that may potentially arise in the future, and simply making your changes in /private/etc/paths
really does propagate them to all users/logins/instances possible - all programs, shells, etc will use the paths in that file to build the base of their $PATH
variable.
To be honest, I’m quite surprised no one else here mentioned this yet. All that messing around with launchd and distractions about SSH-specific uses… this is the solution anyone searching for this basic issue is really looking for - the clean, straight-to-the-source, always-working solution.
By the way, in case you’re wondering, on OS X /etc
is simply a symlink to /private/etc
, so you could just as easily do sudo nano /etc/paths
and get to the same exact place. The above path is just the complete actual path of the file.
Where is the PATH Environment Variable Stored on MacOS?
The files containing the system’s default PATH environment are in two places: