Edit .bashrc vs .bash_profile
TODO: collapasable, copyable, download, etc
When should I edit .bashrc versus .bash_profile?.bashrc
and .bash_profile
are configuration files used by the Bash shell to set environment variables, aliases, and other shell settings. The primary difference between the two lies in when they are loaded.
.bashrc
: This file is executed whenever a new non-login, interactive shell is started. This typically includes terminal sessions that you open within a graphical environment, such as opening a terminal emulator like GNOME Terminal or iTerm2. You should edit.bashrc
when you want to add settings that are applicable to interactive shells, such as aliases, functions, and shell options..bash_profile
(or.profile
or.bash_login
): This file is executed whenever a new login shell is started, such as when you first log in to your computer or connect to a remote machine via SSH. You should edit.bash_profile
when you want to add settings that are applicable to login shells, such as environment variables that should be available system-wide.
In practice, you might find it useful to have some settings available in both interactive and login shells. To achieve this, you can source your .bashrc
file from within your .bash_profile
file. To do this, add the following lines to your .bash_profile
:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
This will ensure that the contents of .bashrc
are also loaded for login shells, allowing you to maintain a single configuration for both types of shells.
Related Chats
Edit .bashrc vs .bash_profile 0.999
zshell 0.482
Update Docker Compose Envvars 0.360
Config Environment Variables Override 0.313
Fixing SSH setup for GitHub 0.302
CI Workflow for Long-Lived Branch 0.286
Env File for Docker 0.280
Nohup com env em shell 0.274