106

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.

3
  • 2
    You should use ~/.profile instead.
    – muru
    Aug 13, 2014 at 10:16
  • 3
    possible duplicate of I can't find .bash_profile
    – Alaa Ali
    Aug 13, 2014 at 10:21
  • 1
    It's pretty common that some configuration file (or even directories) are missing. In that case the software that should read them will use a default configuration and/or read other sources to retrieve the configuration. If you want to modify a configuration file that doesn't exist simply create it first.
    – Bakuriu
    Aug 13, 2014 at 11:33

5 Answers 5

137

Ubuntu uses ~/.profile .

you can create your .bash_profile in Ubuntu but then .profile will not be read.

If we read .profile content :

cat ~/.profile

output

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.

So use ~/.profile instead of ~/.bash_profile

3
  • 1
    .profile didn't work for me. I had to edit .bashrc vim ~/.bashrc then . ~/.bashrc
    – Nahid
    Jun 1, 2018 at 9:29
  • 1
    Using .bash_profile does not work on Ubuntu. It uses Dash as a GUI login shell, not Bash, so bash_profile is not read. Sep 22, 2018 at 19:37
  • If you edit your .profile, you need to log out and back in again to see the changes. Sep 22, 2018 at 19:38
16

When invoking a login shell bash will looks for its config files in this order:

[0] ~/.bash_profile
[1] ~/.bash_login
[2] ~/.profile

After finding the first one, it stops looking for the others so if there is a .bash_profile in my $HOME bash will not look for .bash_login and .profile anymore.

From these three file names, Ubuntu by default uses .profile you can rename it to .bash_profile if you like:

mv ~/.profile ~/.bash_profile

Now if we open a new bash shell using bash -l, su - $USER, sudo -u $USER -i or any other commands that runs bash as a login shell, ~/.bash_profile will get sourced.

Important to note:

What I have talked about till now only applies to Bash itself, when you are logging into the system from a GUI, the display manager is responsible of sourcing the correct files.

Ubuntu uses gdm3 as its display manager, if we take a look at: /etc/gdm3/Xsession we can see that none of the files will get sourced except: .profile:

# First read /etc/profile and .profile
for file in /etc/profile "$HOME/.profile"; do
  if [ -f "$file" ]; then
    source_with_error_check "$file"
  fi
done

so if you are using a GUI to login, keep the file under .profile name otherwise you might miss some variables and settings in your environments.

I guess the better option is creating a symlink to .profile:

ln -s ~/.profile ~/.bash_profile

Now your data lives in .profile, gdm doesn't miss anything, bash loads .bash_profile which is actually .profile, and by editing each of them you get the same result.

Missing .profile?

If you don't have .profile then grab a copy of it from here:

cp /etc/skel/.profile ~/.profile

or

# Remember the note above
cp /etc/skel/.profile ~/.bash_profile
10
  • 1
    But, if Bash is looking for ~/.bash_profile first, then how come it isn't doing this in Ubuntu? Has Ubuntu modified Bash? This seems strange. man bash on Ubuntu still describes how it will look for .bash_profile first. Sep 22, 2018 at 1:50
  • It looks for .bash_profile first it can't find it (because it does not exists) then looks for .bash_login can't find it again (because Ubuntu does not uses these two name) finaly it looks for .profile and yes there it is. So if you create a .bash_profile in ~ then you are overwriting ubuntu's ~/.profile, it's the default behavior of bash nothing has been modified here.
    – Ravexina
    Sep 22, 2018 at 7:59
  • Right, that's what I thought at first, too! And what you describe DOES happen on RHEL. But on Ubuntu, it does not. If I create a .bash_profile, it is not read. I just realized that this is because Ubuntu no longer uses 'Bash' as a GUI login shell. It uses 'Dash' instead. I think this has been true since about 18.04. Sep 22, 2018 at 13:59
  • You are missing the point here. Actually we are talking about the bash itself, what I'm saying here is that Ubuntu creats ’.profile’ and not the others, so if we open a new bash shell (login shell) that's the order of reading these files, doesn't matter what distro we are using. :)
    – Ravexina
    Sep 22, 2018 at 14:54
  • If readers rename .profile to .bash_profile as your answer suggests, then for people on Ubuntu, that file will not be read on login, nor on opening a terminal. You have broken their system. The only way that file will get read is if they launch bash sessions with the '--login' arg to explicitly make it a login shell. That will never happen automatically on their desktop. Sep 22, 2018 at 18:32
5

That means the file does not exist. But, you can create the file and bash executes/sources the file if bash is invoked as a login shell. So evertime you login via a shell (for example via ssh).

If you want the content to execute everytime you open a terminal, then you should modify the .bashrc file instead.

4
  • can you get some idea about why .bash_profile file is missing ?
    – Roledenez
    Aug 13, 2014 at 10:18
  • You can copy it from /etc/skel/ directory.
    – Frantique
    Aug 13, 2014 at 10:19
  • It's a design desicion of canonical. But, that does not mean cannot do it.
    – chaos
    Aug 13, 2014 at 10:25
  • I explained the reason .bash_profile is missing (and does not work) on Ubuntu in comments on other answers. Sep 22, 2018 at 19:48
3

Top answer to use ~/.profile instead of ~/.bash_profile did not work for me.

Modifying .bashrc worked

Just:

vim ~/.bashrc

Note: I'm using Ubuntu WSL.

2
  • In genuine Linux, the .profile is applied when you login to the GUI, or connect remotely, or log in to the console, ie after pressing ctrl+shift+F2. It's supposed to represent the initial time you login to the machine, creating a shell which is parent to all other processes you subsequently create. I suspect that on WSL, there is no such thing as any of this, so your .profile might never be read. Sep 22, 2018 at 19:53
  • same for me. ~/.profile just not loaded by default in ubuntu 18.04 Jun 13, 2019 at 13:41
0

If you mean the .bashrc you will find it in your home folder. If it isn't there, you can copy it from the /etc/skel folder to your home folder.

If you need some more information on this subject, please visit stefaan lippens page.

http://stefaanlippens.net/bashrc_and_others

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .