Lesson 15: Environment variables — $PATH, export, .bashrc
You ran node --version on web-01 and got 'command not found'. node is installed at /opt/node/bin — but the shell doesn't know to look there. echo $PATH shows the list of directories the shell searches for commands. export PATH=$PATH:/opt/node/bin adds the missing entry — works now, but only for this
$PATH is the list of drawers the shell opens when looking for a command. export adds a drawer to the list. .bashrc is the note the shell reads on every startup — that's where you store permanent changes.
- environment variable
- A name=value pair the shell holds and passes to processes it launches. Examples: PATH, HOME, USER. Read a value with $NAME; display all of them with env.
- export
- Marks a variable as 'environmental' — meaning child processes launched by the shell will receive it. export VAR=value defines and exports in one step. Without export, the variable exists only in the current shell.
- $PATH
- A colon-separated list of directories the shell searches for commands. When you run node, the shell walks each directory in PATH looking for a file named node. 'command not found' means it wasn't found in any of them.
- ~/.bashrc
- A file the shell runs automatically on every interactive session start. Add export lines here to keep variables permanent. After editing, source ~/.bashrc reloads it in the current session.