79

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.

  1. Why doesn't it source .profile when opening a terminal?
  2. Why is .profile there if it is not sourced?
  3. How do I know/control what is sourced when a new terminal is opened?
  4. When a new terminal is opened, does it do a "login"?
  5. 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
  • 1,039

2 Answers2

58
  1. Because terminals don't usually run login shells by default. They also usually have options to run login shells, which do source .profile.
  2. To control the behaviour of login shells.
  3. Depends on the shell. For bash, see the set of startup files.
  4. Not in some sense (updating login records, for example).
  5. If you have a folder called bin in $HOME, the default .profile for Ubuntu does add it to your PATH. Since .profile is sourced at login (even with a GUI login), it should be part of your PATH for non-login shells started after a re-login. It isn't wrong if a directory appears twice in PATH, see this U&L question for details.
muru
  • 197,895
  • 55
  • 485
  • 740
  • 6
    OK, now it makes sense. Need to re-login to the GUI to see changes to the .profile. – B Seven Dec 28 '14 at 22:34
  • 2
    @BSeven you can always source it manually for each command-line shell: . .profile or source .profile. – muru Dec 28 '14 at 22:34
  • . .profile is cool and I have never seen it before. Couldn't find much info about the period command. Can you provide a reference and links to any other useful shortcuts? Thank you! – B Seven Dec 28 '14 at 22:39
  • 2
    @BSeven for shell commands like . or source, you can use help: 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. – muru Dec 28 '14 at 22:44
  • I'm on Ubuntu 16.10, when I open the terminal, ~/.profile is not executed. Only when I then type bash -l it is automatically sourced. I don't want to manually source it everytime I start a shell.. – Niklas R Aug 23 '17 at 12:42
  • 3
    @NiklasR https://askubuntu.com/a/598072/158442 – muru Aug 23 '17 at 12:44
  • I put my code in .zshrc instead, changes since Catalina – Sam Aug 05 '21 at 00:19
27

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.

enter image description here

anonymous2
  • 4,298
Billious
  • 371
  • 5
    IIUC 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. – Mu Mind Aug 27 '19 at 21:32
  • It 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. – Mei Mar 29 '21 at 18:07