Summary of MAC system development environment variables

Theory

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 at the system level, and will be loaded when the system starts, and the latter are the current user-level environment variables. The next three are read in 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, the following will be read by analogy document. ~/.bashrc does not have the above rules, it is loaded when the bash shell is opened.

The syntax of PATH is as follows

#中间用冒号隔开
export PATH=$PATH:<PATH 1>:<PATH 2>:<PATH 3>:------:<PATH N>

Science popularization of the above documents

  • /etc/paths (It is recommended to modify this file globally)
    Edit paths, 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 the folder into the Terminal. .

  • /etc/profile (it is recommended not to modify this file)
    global (public) configuration, no matter which user it is, it will read this file when logging in.

  • /etc/bashrc (generally add system-level environment variables in this file)
    global (public) configuration, when the bash shell is executed, no matter what method it is, this file will be read

  • The .profile file sets the environment information for each user of the system. When the user logs in for the first time, the file is executed. And the shell settings are collected from the configuration file in the /etc/profile.d directory. Note:
    If you have the right If /etc/profile is modified, you must restart your modification to take effect. This modification will take effect for every user.

  • ./bashrc Every user who runs the bash shell executes this file. When the bash shell is opened, the file is read.
    Use attention to  modify a certain configuration for all users who use bash and it will take effect if the bash opened later Modify this file, modify this file without restarting, and reopen a bash to take effect.

  • ./bash_profile This file contains bash information specific to your bash shell. This file is read when you log in and every time you open a new shell. (Each user has a .bashrc file in the user directory)
    Note  that it needs to be restarted to take effect. /etc/profile takes effect for all users, and ~/.bash_profile only takes effect for the current user.

source ./.bash_profile or ./.profile environment information takes effect

Global Settings

1. Create a file

sudo touch /etc/paths.d/mysql

2. Open this file with vim (if it is opened with open -t, editing is not allowed):

sudo vim /etc/paths.d/mysql

3. Edit the file, type in the path and save it (close the Terminal window and reopen it to use the mysql command)

/usr/local/mysql/bin

4. $source makes the corresponding configuration take effect

individual user settings

  1. cd ~

  2. vim ~/.bash_profile (add user-level environment variables to any file)

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

Add the above code to ~/.bash_profile.

  1. source Corresponding file effective configuration environment

view PATH


echo $PATH

Guess you like

Origin blog.csdn.net/qq_25062671/article/details/127781580