Mac system as a UNIX system, the same approach to configuring environment variables as UNIX.
The configuration files are loaded in the following order
(1)/etc/profile ( system level )
This is a script file that sets the environment information for each user of the system. The file is executed the first time each user logs on. So the variables set in this file are globally valid.
Note:
(a) The script declares that each time the script is opened, the /ETC/BASHRC file is loaded, and/ETC/BASHRC is the load execution that sets each command-line interaction.
(b) This/etc/path is a system-level load source for variable $path. It is a text file, and each line within the file is a shell-loaded root directory.
(2) ~/.bash_profile, ~/.bash_login, ~/.BASHRC ( user-level )
In the home directory, it will be like one or more of the above files, the Mac system corresponds to only bash_profile this file. This is a script file, which is the file that will be executed when the console is opened.
If there are several, then the order of execution is: ~/.bash_profile, ~/.bash_login, ~/.profile
Note: ~ Under Linux is the variable representing the home.
Application Examples:
For example, after installing the JDK, you need to configure the JAVA_HOME environment variable and the CLASS_PATH environment variable.
Then, there are two ways to configure
(1) Configuring for global users
Vi/etc/profile
editing files, adding environment variable settings
# This directory to the actual configuration
Java_home= "/library/java/javavirtualmachines/jdk1.8.0_131.jdk/contents/home"
Export Java_home
Class_path= "$JAVA _home/lib"
Path= ". $PATH: $JAVA _home/bin"
(2) Configure for current user (my Mac)
VI ~/.bash_profile
Edit this file, same as Add environment variable configuration
# This directory to the actual configuration
Java_home= "/library/java/javavirtualmachines/jdk1.8.0_131.jdk/contents/home"
Export Java_home
Class_path= "$JAVA _home/lib"
Path= ". $PATH: $JAVA _home/bin"
Extended Learning:
(1) Implementation of several environment profiles such as/etc/profile and ~/.bash_profile in Linux
52228672
Java environment variable configuration on Mac