Environment variables are actually stored in process memory, and inherited by child processes. The inherited child process has their inherited environment variable list stored on the process stack.
Initial PATH values are established by the initial process PID 1, but then there are rules about looking at specific system shell initialization scripts that may modify the PATH along the way. There are some in /etc which are shell dependent (such as /etc/z* files). Etresoft has mentioned /etc/paths.d. And then there are the $HOME directory per user shell initialization scripts (such as $HOME/.z*)
If you have not established a specific PATH, then you get the standard process default, which is generally
export PATH="PATH=/usr/bin:/bin:/usr/sbin:/sbin"
If you actually look at what
brew shelling
is doing, it is creating export commands to add Homebrew environment variables, and in some cases it is modifying your existing environment variables, such as your exist PATH environment variable, which gets executed by the 'eval' command. This is what the Homebrew PATH setup command looks like:
export PATH="/usr/local/bin:/usr/local/sbin${PATH+:$PATH}";
Homebrew is a Unix/Linux style package manager for open source software, which is just like all the other Unix/Linux packages managers, in that it totally lacks great documentation, and easy to use operation.
Actually considering how much blog, YouTube, and other Internet coverage Apple gets, I would say Homebrew has better examples, and general support, then the getapp, yum, def, rpm, etc... package managers in the Unix/Linux world.
But in reality, if you are playing with Homebrew, then you should really have a grounding in the Unix/Linux world, or be prepared to do your homework, because any operating system command line is not going to hold your hand, and it is not going to simple minded.
I started working at an ASR33 Teletype back in the early '70's during college (along with 80 columns punched cards), and I have lived in the terminal world professionally for 50+ years, and I while I take a lot of the terminal based environment for granted, there is a lot that I have to do my own homework for, in order to do things. For example, I've been using Google to lookup some Perl syntax this week while I try to write a script that parses an ePub file for the Author's name.
If you are going to launch Applications -> Utilities -> Terminal, then do not expect it to be obvious in how to use it, nor any of the commands and utilities that come with macOS, nor 3rd party open source apps you install.