Glam Prestige Journal

Bright entertainment trends with youth appeal.

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

5 Answers

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

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

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

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

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy