MAC setting environment variable

Posted Jun 15, 20201 min read

  1. Find PATH

    Run pwd to get the absolute path of the current path.

  2. Set the PATH
    Find the location of the .bash_profile file(generally in the user directory) and execute the following command.
    a. touch .bash_profile
    b. open -e .bash_profile
    c. Edit PATH, the command is as follows:

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

    Among them, the ":" colon is used to split multiple environment variable addresses.
    d. source .bash_profile

  3. View PATH

     echo $PATH

In the process of settlement, the relevant information is as follows:

  1. About the loading order of MAC environment variables
  2. vim exit command
    :q means exit
    :wq means save and exit
    :q! means force to exit without saving
  3. If the setting is wrong, commands such as ls cannot be used, use the following command to temporarily restore.
    export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/userName/bin