2

I have just installed LaTEX and need to add the path to my $PATH variable so I can use the command. I have tried adding path (/usr/local/texlive/2015/bin/x86_64-linux) to my .bash_profile and when I restart the terminal and echo $PATH, it does not show my addition. The relevant code that I added:

PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/texlive/2015/bin/x86_64-linux
export PATH

I have tried to add path to /etc/profile but without success. Any advice would be greatly appreciated.

muru
  • 72,889
D B
  • 31
  • 1
  • 1
  • 3
  • Thank you very much for your answers, Eric and Cyrus, both of them are very useful. I rebooted the computer and now the path is added: success! Since the path is going to be read from now on (because at every login .bash_profile will be read), I take that it is not necessary anymore for me to add it to .bashrc, right? – D B Dec 13 '15 at 20:48
  • Right, and as Giles pointed out, you probably shouldn't have put it there anyway, even though that's what i had recommended – Eric Renouf Dec 15 '15 at 20:33

3 Answers3

2

Your code is correct. The location may or may not be correct. .bash_profile is read if your login shell is bash and you log in in text mode (on a text console or over the network). However, if you log in at a graphical prompt, on most systems, .bash_profile is not read, but .profile is. To avoid duplication, I recommend putting all environment variable assignments in .profile and using the following code for .bash_profile to do the right thing for both interactive and non-interactive login shells:

. ~/.profile
case $- in *i*) . ~/.bashrc;; esac

Don't put environment variable definitions such as PATH in .bashrc. This would only work in programs invoked from terminals, not e.g. if your editor attempts to run LaTeX automatically.

Since .profile (or .bash_profile) is only read when you log in, the setting won't take effect until you log out and back in. You can make the setting take effect in a terminal (including programs started from that terminal) by typing (or pasting) the PATH=… command there. Some desktop environments and window managers let you modify their environment variables; how to do this depends on the desktop environment.

0

.bash_profile is read only during a login, and opening a terminal is not a login. You should probably ad this to your .bashrc instead so interactive shells will read it.

You can see some more discussion about this at this question

Eric Renouf
  • 18,431
0

Answer from Gilles does not account for non-login interactive shell


Summary:

If we need to add a PATH to both interactive and non-interative environment, we need to account for several cases:

  1. non-login interactive bash shell

Only read .bashrc, not .profile nor .bash_profile

  1. login interactive bash shell

Read .profile (and read .bashrc by default in .profile)

or .bash_profile if exists

  1. login non-interactive shell

Read .profile only (or .bash_profile if exists)

will not read .bashrc by default and the search for .bashrc in .profile shoudln't return true as below

if [ -n '$BASH_VERSION']; then

  1. non-login non-interactive shell

Not reading anything by default


note: my answer also might be not entirely correct, writing an answer over here just in case


Source:

  1. https://askubuntu.com/questions/247738/why-is-etc-profile-not-invoked-for-non-login-shells
    • not entirely correct, the wrong part is non-interactive shell doesn't invoke .bashrc
  2. https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

More:

  1. login/non-login and interactive/non-interactive shells

Test for login non-interative case

To test for how .profile will run under login non-interative case, can add in some echo to files under if else statement

~/.profile

if [ -n '$BASH_VERSION']; then echo test > test.txt else echo bash version missing > test.txt fi

wltprgm
  • 91