Fundamentals 6 min read

Understanding Linux profile, bash_profile, and bashrc: Key Differences and Usage

This article explains the roles of the three frequently used Linux configuration files—/etc/profile, ~/.bashrc, and ~/.bash_profile—detailing how they set system-wide or user-specific environment variables, when they are executed, and how to modify them correctly.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Understanding Linux profile, bash_profile, and bashrc: Key Differences and Usage

Understanding Linux profile, bash_profile, and bashrc

Linux systems frequently use three configuration files: /etc/profile, ~/.bashrc, and ~/.bash_profile. Because their names are similar, users often confuse their purposes, so this guide clarifies each file's role and differences.

1. profile file

1.1 Purpose of profile

The /etc/profile file sets system‑wide environment variables and startup programs; changes affect all users.

It is executed when a user logs in (login shell) and also reads additional configuration files from /etc/profile.d.

1.2 Adding environment variables in profile

Generally, adding variables to /etc/profile is discouraged because it impacts every user. If necessary, you can add a line such as: export HOST=magedu.com After editing, you must log out and back in, or run source /etc/profile to apply the changes immediately. Verify with echo $HOST.

2. bashrc file

The bashrc file configures functions or aliases. There are two levels:

System‑wide: /etc/bashrc (affects all users)

User‑specific: ~/.bashrc (affects the current user)

bashrc is read by the Bash shell for each interactive non‑login session.

3. bash_profile file

~/.bash_profile

is a user‑level file that is executed only for the login shell of a single user. It can also set environment variables and start programs, but its scope is limited to that user.

Like /etc/profile, it runs at login and can be used to configure user‑specific settings.

4. Summary of differences

In short: /etc/profile and /etc/bashrc define system‑wide environment settings. ~/.profile, ~/.bashrc, and ~/.bash_profile define user‑specific settings, with ~/.profile executed once at login and ~/.bashrc executed for each interactive shell.

When a shell starts, the reading order is:

Read /etc/profile and files in /etc/profile.d (and /etc/inputrc if present).

Read user‑level login files in order: ~/.bash_profile, ~/.bash_login, then ~/.profile (the first that exists is used).

Finally, read ~/.bashrc for interactive shells.

Both ~/.profile and ~/.bashrc allow personal customization; ~/.profile runs only once at login, while ~/.bashrc runs for each new Bash session.

Shell configuration file reading order diagram
Shell configuration file reading order diagram
environment variablesProfilebash_profilebashrc
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.