Skip to content

Understanding Bash Startup Files: Profile and Bashrc on Linux

Updated 3 min read

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 - or bash -l.
  • Interactive non-login shell: a new terminal window on a desktop, or typing bash in 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 in ssh 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/bashrc also runs /etc/profile.d/*.sh for these shells.
  • The default ~/.bashrc also runs every file in ~/.bashrc.d/, a tidy place for your own additions.

Ubuntu and Debian

  • Login shell: /etc/profile (which runs /etc/bash.bashrc for 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_login and ~/.profile that exists. If you create a ~/.bash_profile on Ubuntu or Debian, ~/.profile is no longer read, and neither is ~/.bashrc unless you source it yourself.

Where to put what

  • Environment variables for one user (PATH, EDITOR): ~/.bash_profile on AlmaLinux, Rocky Linux and RHEL, ~/.profile on 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/profile or /etc/bashrc directly, 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.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket