Several Methods for setting the path environment variable for MAC: Environment Variable path
Mac generally uses bash as the default shell
The Mac system environment variables are loaded in the following sequence:
/Etc/profile/etc/paths ~ /. Bash_profile ~ /. Bash_login ~ /. Profile ~ /. Bashrc
Of course,/etc/profile and/etc/paths are system-level, which will be loaded when the system starts. The following are the environment variables of the current user level. The last three are read in the previous and subsequent order. If ~ /. Bash_profile file exists, then the following files will be ignored and not read. If ~ /. Bash_profile file does not exist, so it reads the following files accordingly .~ /. Bashrc does not have the above rules. It is loaded when bash shell is opened.
Unless otherwise specified, the PATH syntax is :-------------------
# Export PATH = $ PATH: <PATH 1 >:< PATH 2 >:< PATH 3 >:------: <path n>
(1) Global settings the following file settings are global and the root permission is required for modification.
1)/etc/paths (it is recommended to modify this file globally)
Edit paths and add the environment variable to the paths file.
Hint: when entering environment variables, you don't need to input them one by one. You just need to drag the folder to Terminal.
2)/etc/profile (this file is not recommended) Global (public) configuration. No matter which user, the file will be read at login.
3)/etc/bashrc (generally adding system-level environment variables to this file) Global (public) configuration. During bash shell execution, the file is read in any way.
4)
1. Create a file:
Sudo touch/etc/paths. d/mysql
2. open the file with vim (if it is opened in open-t mode, it cannot be edited ):
Sudo vim/etc/paths. d/mysql
3. edit the file, type the path, and save it. (close the Terminal window and open another one. You can use the mysql Command)
/Usr/local/mysql/bin
It is said that this allows you to generate new files by yourself without storing all the variables in a paths file for convenient management.
(2) individual user settings
1 )~ /. Bash_profile (add user-level environment variables to any file)
(Note: In Linux, It Is. bashrc and Mac is. bash_profile)
This file is read only when bash shell is executed in login mode. This file is only executed once! By default, it sets some environment variables.
SET command alias ll = 'LS-la'
Set environment variables:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
2 )~ /. Bashrc same as above
To take effect immediately, run the following statement:
$ Source corresponding file
Generally, after the environment variable is changed, it takes effect after restart.