█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/DevOps and Infrastructure/Linux and the Command Line/Environment and Configuration
35 minBeginner

Environment and Configuration

After this lesson, you will be able to: Configure your shell environment with confidence: the startup files, environment variables and PATH, aliases and functions, and dotfiles you version in Git so any machine feels like home.

Every command you run inherits an environment: variables, a PATH that decides which programs are found, and a shell configured by startup files. Knowing how that environment is assembled is the difference between 'command not found' being a mystery and being a thirty-second fix. This lesson also covers dotfiles, the configuration that experienced engineers carry from machine to machine.

Prerequisites:Shell Scripting

The shell startup files, and which one runs when

The confusion that trips everyone up: which file does bash actually read? A login shell (when you SSH in, or log in at a console) reads `~/.bash_profile` (or `~/.profile` if that is absent). A non-login interactive shell (a new terminal tab on an already-logged-in machine) reads `~/.bashrc`. Because you want the same setup in both, the common pattern is to put everything in `~/.bashrc` and have `~/.bash_profile` source it with `[ -f ~/.bashrc ] && . ~/.bashrc`. Zsh users have the parallel `~/.zshrc`. Knowing this is why your alias works in one terminal and not another: you put it in the file that shell did not read.

Environment variables and PATH

PATH is just a colon-separated list of directories the shell searches, in order, to find a command.

tsx
# See your PATH
echo $PATH
# /usr/local/bin:/usr/bin:/bin:/home/you/.local/bin
# 'command not found' almost always means the program's dir isn't on PATH.
# Add a directory to PATH (put this in ~/.bashrc to make it permanent):
export PATH="$HOME/.local/bin:$PATH" # prepend so it wins over system copies
# Set an environment variable for the current shell + child processes:
export EDITOR=vim
export NODE_ENV=production
# See one variable / all of them:
echo $EDITOR
printenv | sort
# Set a variable for ONE command only (not exported permanently):
DEBUG=1 ./myscript.sh

Aliases and shell functions

Aliases are shortcuts for commands you type constantly. Functions handle the cases aliases can't (arguments in the middle, logic).

tsx
# Aliases (put in ~/.bashrc)
alias ll='ls -lah'
alias gs='git status'
alias ..='cd ..'
alias k='kubectl'
# A function when you need an argument or logic:
mkcd() {
mkdir -p "$1" && cd "$1"
}
# usage: mkcd new-project
# Reload your config after editing without opening a new terminal:
source ~/.bashrc

💡 Dotfiles: your environment, versioned

The config files in your home directory that start with a dot (`.bashrc`, `.gitconfig`, `.vimrc`, `.ssh/config`) are called dotfiles. Experienced engineers keep them in a Git repository (a 'dotfiles repo') so a brand-new laptop or server becomes their familiar environment in one `git clone` and a symlink script. It is also a great public GitHub repo: it shows you live in the terminal. Start one the day you have three aliases worth keeping. Never commit secrets (tokens, private keys) into it; keep those in a separate, untracked file.

Common mistakes only experienced engineers catch

Putting aliases in `~/.bash_profile` and wondering why a new terminal tab ignores them (tabs read `~/.bashrc`). Appending to PATH when you meant to override: `PATH="$PATH:/new"` puts your dir last, so a system binary of the same name still wins. Prepend when you want yours to win. Editing `~/.bashrc` and expecting the current shell to update without `source ~/.bashrc` or a new terminal. Setting a variable without `export`, so child processes (your scripts, your app) never see it. Committing a token or private key into a public dotfiles repo. Rotate it immediately if you do.

Quick Check

You add `alias gs='git status'` to ~/.bashrc, but a freshly opened login SSH session ignores it. Why?

Pick the correct explanation.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←Shell Scripting
Back to Linux and the Command Line
SSH→