Questions tagged [.profile]

A user-specific (not systemwide) configuration script executed when starting login shells.

.profile is a file in each user's home directory (for example /home/octavia/.profile) that is run for login shells only. This means it will definitely be read by bash when the user logs in on a TTY (virtual terminal), but will not usually be read by bash when opening a terminal emulator inside a graphical shell. However, since the file is usually read by the graphical shell when the user logs in, variables set there may be inherited by other shells. It is therefore one place that may be used to set or modify some user-specific environment variables.

The file .profile is normally read in Ubuntu because we do not typically have a file ~/.bash_login, which would be read in preference to ~/.profile if it existed, or a file ~/.bash_profile which would be read in preference to either of those files.

Here is an example of a .profile in Ubuntu

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

As shown, ~/.profile can be used to set a for the user, overriding the one set systemwide by /etc/profile.

The code then checks to see whether the shell being run is a bash shell, and if it is, reads the user's ~/.bashrc. This means that any customisations (such as PS1 definition, aliases and functions) made in ~/.bashrc will be available in shells that read ~/.profile but not ~/.bashrc directly, unless they are overidden by commands later in the file.

Finally, the code checks to see whether the user has a directory ~/bin and if it does exist, it is added to their PATH variable. This means that users can place applications in this directory, and call them without the full path.

Additional customisations can be added to the end of the file.

Some popular questions:

What are login and non-login shells?

Why does Ubuntu's default ~/.profile source ~/.bashrc?

207 questions
257
votes
7 answers

Why ~/.bash_profile is not getting sourced when opening a terminal?

Problem I have an Ubuntu 11.04 Virtual Machine and I wanted to set up my Java development environment. I did as follows sudo apt-get install openjdk-6-jdk Added the following entries to ~/.bash_profile export…
Viriato
  • 2,781
  • 3
  • 16
  • 10
107
votes
5 answers

I cannot find .bash_profile in ubuntu

I can't find .bash_profile in Ubuntu 14.04 in my /home/user directory. I used the ls -a command to see the .bash_profile, but there isn't such a file.
Roledenez
  • 1,205
92
votes
2 answers

What are login and non-login shells?

It is said that settings for non login shell to go into .bashrc file and login shell settings to go into .profile file. What is really meant by login and non-login shells? Please explain without using technical jargon as far as possible.
DUKE
  • 3,388
83
votes
5 answers

Why are scripts in /etc/profile.d/ being ignored (system-wide bash aliases)?

I'm new to Ubuntu. I'm running 13.10 Desktop. I wanted to set some system wide aliases and a custom prompt for bash. I found this article: https://help.ubuntu.com/community/EnvironmentVariables Following the advice in this article, I created…
Drew
  • 941
82
votes
4 answers

Permanent PATH variable

How will I make this /media/De Soft/mongodb/bin PATH variable permanent? Everyone is saying "export PATH=$PATH:media/De\ Soft/mongodb/bin to your ~/.profile, or .bashrc, or .zshenv depending on your shell". I don't know what is ~/.profile, or…
Towhid
  • 4,195
81
votes
2 answers

Why isn't .profile sourced when opening a terminal?

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…
B Seven
  • 1,069
56
votes
3 answers

Sequence of scripts sourced upon login

I would like to concentrate all my login config in my ~/.bash_profile. There was a ~/.bashrc there by default but I replaced it with a ~/.bash_profile. However, when I log in, something before my ~/.bash_profile gets sourced and displays the…
amphibient
  • 1,287
53
votes
6 answers

Why is /etc/profile not being loaded during non-login bash shell sessions?

For 11.04, I did a fresh install of my system. Part of that install was to install rvm, which sticks a rvm.sh in /etc/profile.d/. This doesn't work as /etc/profile (which loads each +r in /etc/profile.d/*.sh) is not being loaded. According to the…
Marc
  • 533
52
votes
3 answers

What goes in ~/.profile and ~/.bashrc?

I'm having trouble wrapping my head around what belongs in ~/.profile and what belongs in ~/.bashrc. From what I've read, it seems to me that ~/.profile should be used for environment variables and ~/.bashrc for aliases, functions, and the like. If…
MDeBusk
  • 1,386
33
votes
2 answers

Why does Ubuntu's default ~/.profile source ~/.bashrc?

These are the contents of the stock ~/.profile that came with my 13.10 (commented lines removed): if [ -n "$BASH_VERSION" ]; then if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi if [ -d "$HOME/bin" ] ; then …
terdon
  • 104,119
30
votes
4 answers

Configure gnome-terminal to start bash as a login shell, doesn't read .bashrc

I'm trying to integrate RVM with gnome-terminal. Per default, gnome-terminal does not start bash as a login shell. I enabled run command as a login shell as suggested in this answer about the same topic setting up RVM, but when I do this the .bashrc…
21
votes
2 answers

how to reset ~/.profile to default

I have been playing around with the ~/.profile file trying to add something permanently to my $PATH variable and it seems i have done some damage. I can't log into ubuntu now. When I enter my password the screen goes black for 1 second and then it…
Adrian Buzea
  • 333
  • 1
  • 3
  • 6
18
votes
1 answer

What can cause my .profile file to not be loaded when a new terminal shell is initialized?

There are no errors in xsession and I don't have a .bash_login or .bash_profile file, so I'm 100% certain neither of those is loaded and thus cancels .profile loading. When I rename the .profile to .bash_profile and open a new terminal window, it…
Swader
  • 325
18
votes
1 answer

How can I restore /etc/profile?

I'm working on a bash script that appends to /etc/profile, but instead of appending, I accidentally wrote over it, losing all of its content. How can I restore the file? Is there a system default profile that I can copy to restore my /etc/profile? I…
Alex
  • 433
17
votes
5 answers

Why is setting alias in .profile not working?

I have this as the last line in my .profile: alias gl="cd /home/jrenner/glances/glances" yet even after reboot I get command not found when typing gl. What is happening? I am logged in as the correct user.
1
2 3
13 14