Updated: 28 September 2026 · Applies to: bash 5.1 to 5.3 on AlmaLinux and Rocky Linux 9 and 10, RHEL 9 and 10, Ubuntu 24.04 and 26.04, Debian 13
When bash starts, it reads a few startup files that set environment variables, aliases and the prompt. Which files it reads depends on how the shell was started, and the file names differ between the Red Hat family and Ubuntu/Debian. This is why a setting sometimes works in one terminal but not in another. We traced which files are read on AlmaLinux 10 and Debian 13.
Login shell or not
- Login shell: an SSH login, a console login,
su -orbash -l. - Interactive non-login shell: a new terminal window on a desktop, or typing
bashin an existing shell. - Non-interactive shell: a script, a cron job or
bash -c "...". It reads none of the files below (only the file named in$BASH_ENV, if set). One exception: a command run over SSH, as inssh server 'command', reads~/.bashrc.
AlmaLinux, Rocky Linux and RHEL
- Login shell:
/etc/profile(which runs/etc/profile.d/*.sh), then~/.bash_profile, which runs~/.bashrc, which runs/etc/bashrc. - Interactive non-login shell:
~/.bashrc, which runs/etc/bashrc;/etc/bashrcalso runs/etc/profile.d/*.shfor these shells. - The default
~/.bashrcalso runs every file in~/.bashrc.d/, a tidy place for your own additions.
Ubuntu and Debian
- Login shell:
/etc/profile(which runs/etc/bash.bashrcfor interactive bash and/etc/profile.d/*.sh), then~/.profile, which runs~/.bashrc. - Interactive non-login shell:
/etc/bash.bashrc, then~/.bashrc. - Watch out: bash reads only the first of
~/.bash_profile,~/.bash_loginand~/.profilethat exists. If you create a~/.bash_profileon Ubuntu or Debian,~/.profileis no longer read, and neither is~/.bashrcunless you source it yourself.
Where to put what
- Environment variables for one user (
PATH,EDITOR):~/.bash_profileon AlmaLinux, Rocky Linux and RHEL,~/.profileon Ubuntu and Debian. - Aliases, functions and the prompt for one user:
~/.bashrc, because non-login shells do not read the profile files. - Settings for all users: a new file in
/etc/profile.d/, for example/etc/profile.d/custom.sh. Do not edit/etc/profileor/etc/bashrcdirectly, because package updates may replace them. - Variables for cron jobs and systemd services: set them in the crontab or the service unit (
Environment=), because these do not read any profile file.
Apply changes and check
source ~/.bashrc # reload in the current shell bash -lc 'echo $PATH' # what a login shell sees shopt -q login_shell && echo login || echo "not a login shell"
Other shells use their own files: zsh reads ~/.zshrc and ~/.zprofile, ksh reads ~/.profile and the file named in $ENV.
Official documentation: Bash manual: startup files.