Where are Environment Variables stored in Ubuntu

The environment variables can be stored in various configuration files depending upon the program that you are referring to as well the scope - system-wide or user-specific.

System-Wide Environment Variables:

    You can find the system-wide environment variables under /etc/environment file.

    # cat /etc/environment

User-Specific Environment Variables:

    Based on what shell you use, you can find them under the ~/.bashrc or ~/.zshrc files under the home directory.

    cat ~/.bashrc
    # ~/.bashrc: executed by bash(1) for non-login shells.
    # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
    # for examples
    # If not running interactively, don't do anything
    [ -z "$PS1" ] && return
    # don't put duplicate lines in the history. See bash(1) for more options
    # ... or force ignoredups and ignorespace
    # append to the history file, don't overwrite it
    shopt -s histappend
    # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
Location where environment variables are stored Ubuntu

Know the Temporary Environment variables:

    If you are looking for the temporary environment variables set for the current session then you can make use of the printenv command.

    # printenv

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap