The environment variables of the Mac system, the loading order is:
/etc/profile /etc/paths ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc
/etc/profile and /etc/paths are system-level, they will be loaded when the system starts, and the next few are the current user-level environment variables. The last three files are read in the order from front to back. If the /.bash_profile file exists, the next few files will be ignored and not read. If the /.bash_profile file does not exist, only And so on to read the following files. ~/.bashrc does not have the above rules, it is loaded when the bash shell is opened.
-
/etc/paths (It is recommended to modify this file globally)
Edit paths and set the environment variable Add to the paths file, one path per line
Hint: When entering environment variables, you don’t need to enter them one by one, just drag the folder to the Terminal. -
/etc/profile (It is recommended not to modify this file)
Global (public) configuration, no matter which user it is, this file will be read when logging in. -
/etc/bashrc (Generally add system-level environment variables to this file)
Global (public) configuration, when the bash shell is executed, no matter what way, This file will be read -
. The profile file sets environmental information for each user of the system. When the user logs in for the first time, the file is executed. And from /etc/ Collect shell settings in the configuration file of the profile.d directory
Notes for use: If you make changes to /etc/profile, you must restart your changes to take effect. This change is effective for every All users are effective. -
./bashrc Every user running the bash shell executes this file. When the bash shell is opened, the file is read.
Notes for use< /strong>You can modify this file if you modify a certain configuration for all users who use bash and the bash opened in the future will take effect. Modify this file without restarting, and reopen a bash to take effect. -
./bash_profile This file contains bash information dedicated to your bash shell. This file is read when you log in and every time you open a new shell. (every Each user has a .bashrc file, in the user directory)
Notes for use need to be restarted to take effect, /etc/profile is effective for all users, ~/.bash_profile is only for the current user Take effect.
source ./.bash_profile or ./.profile environment information takes effect
Operation section
Global settings
- Create a file:
sudo touch /etc/paths.d/mysql
- < li>Open this file with vim (if it is opened with open -t, editing is not allowed):
sudo vim /etc/paths.d/ mysql
- Edit the file, type in the path and save it (close the Terminal window and reopen one, you can use the mysql command)
< pre class="hljs bash">/usr/local/mysql/bin
- $ source the corresponding file Effective configuration environment
Single user settings
-
cd ~
-
vim ~/. bash_profile (Add user-level environment variables to any file)
export PATH=/opt/< span class="hljs-built_in">local/bin:/opt/local/sbin:$PATH
Add the above code to ~/.bash_profile.
- Source the corresponding file effective configuration environment
Check PATH
echo $PATH
The environment variables of the Mac system, the loading order is:
/etc/profile /etc/paths ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc
/etc/profile and /etc/paths is at the system level and will be loaded when the system is started. The next few are environment variables at the current user level. The last three files are read in the order from front to back. If the /.bash_profile file exists, the next few files will be ignored and not read. If the /.bash_profile file does not exist, only And so on to read the following files. ~/.bashrc does not have the above rules, it is loaded when the bash shell is opened.
-
/etc/paths (It is recommended to modify this file globally)
Edit paths and add environment variables to the paths file, one line A path
Hint: When entering environment variables, you don’t need to enter them one by one, just drag the folder to the Terminal. -
/etc/profile (It is recommended not to modify this file)
Global (public) configuration, no matter which user it is, this file will be read when logging in. -
/etc/bashrc (Generally add system-level environment variables to this file)
Global (public) configuration, when the bash shell is executed, no matter what way, This file will be read -
. The profile file sets environmental information for each user of the system. When the user logs in for the first time, the file is executed. And from /etc/ Collect shell settings in the configuration file of the profile.d directory
Notes for use: If you make changes to /etc/profile, you must restart your changes to take effect. This change is effective for every All users are effective. -
./bashrc Every user running the bash shell executes this file. When the bash shell is opened, the file is read.
Notes for use< /strong>You can modify this file if you modify a certain configuration for all users who use bash and the bash opened in the future will take effect. Modify this file without restarting, and reopen a bash to take effect. -
./bash_profile This file contains bash information dedicated to your bash shell. This file is read when you log in and every time you open a new shell. (every Each user has a .bashrc file, in the user directory)
Notes for use need to be restarted to take effect, /etc/profile is effective for all users, ~/.bash_profile is only for the current user Take effect.
source ./.bash_profile or ./.profile environment information takes effect
Operation section
Global settings
- Create a file:
sudo touch /etc/paths.d/mysql
- < li>Open this file with vim (if it is opened with open -t, editing is not allowed):
sudo vim /etc/paths.d/ mysql
- Edit the file, type in the path and save it (close the Terminal window and reopen one, you can use the mysql command)
< pre class="hljs bash">/usr/local/mysql/bin
- $ source the corresponding file Effective configuration environment
Single user settings
-
cd ~
-
vim ~/. bash_profile (Add user-level environment variables to any file)
export PATH=/opt/< span class="hljs-built_in">local/bin:/opt/local/sbin:$PATH
Add the above code to ~/.bash_profile.
- Source the corresponding file effective configuration environment
Check PATH
echo $PATH
-
/etc/paths (It is recommended to modify this file globally)
Edit paths and add environment variables to the paths file, one path per line
Hint: When entering environment variables, you don’t need to enter them one by one, just drag Just move the folder to Terminal. -
/etc/profile (It is recommended not to modify this file)
Global (public) configuration, no matter which user it is, this file will be read when logging in. -
/etc/bashrc (Generally add system-level environment variables to this file)
Global (public) configuration, when the bash shell is executed, no matter what way, This file will be read -
. The profile file sets environmental information for each user of the system. When the user logs in for the first time, the file is executed. And from /etc/ Collect shell settings in the configuration file of the profile.d directory
Notes for use: If you make changes to /etc/profile, you must restart your changes to take effect. This change is effective for every All users are effective. -
./bashrc Every user running the bash shell executes this file. When the bash shell is opened, the file is read.
Notes for use< /strong>You can modify this file if you modify a certain configuration for all users who use bash and the bash opened in the future will take effect. Modify this file without restarting, and reopen a bash to take effect. -
./bash_profile This file contains bash information dedicated to your bash shell. This file is read when you log in and every time you open a new shell. (every Each user has a .bashrc file, in the user directory)
Notes for use need to be restarted to take effect, /etc/profile is effective for all users, ~/.bash_profile is only for the current user Take effect.
source ./.bash_profile or ./.profile environment information takes effect
Operation section
Global settings
- Create a file:
sudo touch /etc/paths.d/mysql
- < li>Open this file with vim (if it is opened with open -t, editing is not allowed):
sudo vim /etc/paths.d/ mysql
- Edit the file, type in the path and save it (close the Terminal window and reopen one, you can use the mysql command)
< pre class="hljs bash">/usr/local/mysql/bin
- $ source the corresponding file Effective configuration environment
Single user settings
-
cd ~
-
vim ~/. bash_profile (Add user-level environment variables to any file)
export PATH=/opt/< span class="hljs-built_in">local/bin:/opt/local/sbin:$PATH
Add the above code to ~/.bash_profile.
- Source the corresponding file effective configuration environment
Check PATH
echo $PATH