Why isn't .profile sourced when opening a terminal?
65,013
Solution 1
- Because terminals don't usually run login shells by default. They also usually have options to run login shells, which do source
.profile
. - To control the behaviour of login shells.
- Depends on the shell. For
bash
, see the set of startup files. - Not in some sense (updating login records, for example).
- If you have a folder called
bin
in$HOME
, the default.profile
for Ubuntu does add it to yourPATH
. Since.profile
is sourced at login (even with a GUI login), it should be part of yourPATH
for non-login shells started after a re-login. It isn't wrong if a directory appears twice inPATH
, see this U&L question for details.
Solution 2
I found I had to edit the Default profile. In the terminal, click Preferences > Profiles > Edit > Command > Run command as login shell
Afterwards new terminals would source .profile script.
Related videos on Youtube
Author by
B Seven
Status: Hood Rails on HTTP/2: Rails HTTP/2 Rack Gems: Rack Crud Rack Routing Capybara Jasmine
Updated on September 18, 2022Comments
-
B Seven over 1 year
Just installed Ubuntu 14.04.1 LTS.
According to .profile,
# ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash, if ~/.bash_profile or ~/.bash_login exists.
There is no ~/.bash_profile or ~/.bash_login.
It does not seem to source .profile when opening a terminal.
- Why doesn't it source .profile when opening a terminal?
- Why is .profile there if it is not sourced?
- How do I know/control what is sourced when a new terminal is opened?
- When a new terminal is opened, does it do a "login"?
- Where is a good place to add $HOME/bin to my path? .bashrc? Will that cause a problem because .profile has the same code?
-
B Seven over 9 yearsOK, now it makes sense. Need to re-login to the GUI to see changes to the
.profile
. -
muru over 9 years@BSeven you can always source it manually for each command-line shell:
. .profile
orsource .profile
. -
muru over 9 years@BSeven for shell commands like
.
orsource
, you can usehelp
:help .
, for example. In general, see the TLDP Bash Beginner's Guide, Chapter 3. The Bash Beginner's Guide is somewhat dated in some places, but good for a starting point. Or see other links in one of my other answers. -
Niklas R over 6 yearsI'm on Ubuntu 16.10, when I open the terminal,
~/.profile
is not executed. Only when I then typebash -l
it is automatically sourced. I don't want to manually source it everytime I start a shell.. -
muru over 6 years@NiklasR askubuntu.com/a/598072/158442
-
Seyed Mohammad over 4 yearsIIUC this is a hack because normally .profile is supposed to have been sourced before starting the GUI terminal and it's redundant to source it again each time you spawn a terminal window.
-
David about 3 yearsIt isn't a hack, but it could be redundant if, for example, your login profile starts up an initial of instance of some various GUI programs, and so forth. But if you want - for instance - vi editing to be enabled every time you open a shell, you may have to use this option, making the shell read it's profile files.
-
Sam over 2 yearsI put my code in
.zshrc
instead, changes since Catalina