Unix Terminal Environment Variables Commands Tutorial

  • Sonar Systems admin
    Likes 0

    Problem Description

    Environment variables are a must use tool for developers, here is a easy list of commands you will need to know.

    Solution Description

    What are environment variables?
    Environment variables can be thought of as global variables that can be accessed by different applications. Imagine if several applications were using a shortcut key for your desktop, they could and would use an environment variable that pointed to your desktop which could be easily updated if need be. Environment variables don't have to be paths, they can store other data.

    Retrieve list of existing environment variables
    printenv - shows all environment variable
    set - show complete list of shell variables


    Retrieve a specific environment variable
    echo $NAME


    Set environment variables
    touch ~/.bash_profile // creates a file if it doesn't exist

    nano ~/.bash_profile // opens the bash_profile file in terminal
    // or open like this
    open ~/.bash_profile // opens the bash_profile file using a text editor

    export VARIABLE_NAME=data // set/update environment variable

    source ~/.bash_profile // run bash_profile file


    Update environment variable
    same as setting an environment variable


    Delete environment variable
    touch ~/.bash_profile // creates a file if it doesn't exist

    nano ~/.bash_profile // opens the bash_profile file in terminal
    // or open like this
    open ~/.bash_profile // opens the bash_profile file using a text editor

    unset VARIABLE_NAME // deletes environment variable

    source ~/.bash_profile // run bash_profile file

Login to reply