Post

MacOS Environment Variables

  • To display the list of currently set environment variables:
    1
    
    printenv
    
  • To display the value of any specific environment variable:
    1
    
    echo $[variable name]
    
  • To check the value of the PATH variable which stores a list of directories with executable files:
    1
    
    echo $PATH
    
  • To set a temporary environment variable:
    1
    
    export [variable_name]=[variable_value]
    
  • To add value to an existing environment variable:
    1
    
    export [existing_variable_name]=[new_variable_value]:$[existing_variable_name]
    

    Example:

    1
    
    export PATH=/Users/exec/tok:$PATH
    
  • To set permanent environment variable
    1. Find the path to .bash_profile using:
      1
      
      ~/.bash_profile
      
    2. Open the .bash_profile file with a text editor and add the new environmental variable to the end of the file using:
      1
      
      export [variable_name]=[variable_value]
      
    3. Save the file and refresh the terminal using the below command or restart the terminal.
      1
      
      source ~/.bash_profile
      
  • To unset the environmental variable:
    1
    
    unset [variable =_name]
    
This post is licensed under CC BY 4.0 by the author.