0

Recent instructional video I was watching said to put your export PATH="$PATH..." statement in your .profile and after sourcing manually in the terminal to append ". ~/.profile" to your .bashrc file as well. However, when I do this it messes up my terminal when I open a new tab rather than allows me to access the bin from the path.

Did this behavior change? If so, where is the correct place to source my profile so that opening a new tab or terminal window gives access to the same commands/executables in the bin folder I am referencing?

Mainly need guidance on ensuring that changes to .profile did not need to be referenced elsewhere. This was understood and picked up by the person who answered my question - marked as answer below.

Edited for clarity and to fix a typo.

3 Answers3

2

The answer is: nowhere. .profile is sourced automatically each time you log in. .bashrc is sourced each time an interactive terminal starts. There is no use in trying to source .profile once more in .bashrc, which actually causes an infinite loop on Ubuntu because .bashrc is sourced in .profile.

So far with respect to the problem you ask about, problem Y.

With respect to your real problem, X, i.e., having a bin folder in your PATH: no other action is needed than 1) creating ~/bin (and/or ~/.local/bin), then 2) log out and back in. If these directories exist, they are automatically added to your PATH (you can see the code that does that in ~/.profile). To keep things neat, do not add other directories to your PATH, although you could do so in your .profile file.

vanadium
  • 97,564
2

Ubuntu has a non-standard setup it has inherited from Debian and its .bashrc file is sourced by .profile:

$ grep -A1 bashrc /etc/skel/.profile 
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi

So if you then also source .profile from ~/.bashrc you get into an infinite loop, which will break your shell.

The right way to add a new directory to your $PATH is to edit ~/.profile. The file is sourced every time you start a new login shell and, on Ubuntu systems, is also sourced when you log in graphically. After modifying ~/.profile to add something to the $PATH, the change will take effect next time you log in. So instead of making ~/.bashrc source ~/.profile, just logout and log back in again and your changes will be there.

terdon
  • 104,119
-1

export PATH=$PATH':<path>:<another path>' appends paths to the PATH environment variable. It is the paths that should be used when locating executable files (programs).

If you have a program in /home/<user>/bin called 'Gloop', and you type Gloop at the command prompt in the bash shell (terminal), it normally won't execute, because /home/<user>/bin is not in the PATH variable, so bash doesn't know to look there for programs names.

So, you would go up to the first line, and insert /home/<user>/bin with your actual username, in place of <path>, and then you can type Gloop at the command line, and it will launch.

But sometimes you want to execute a program, but you don't want it in the PATH.

Then, you do ./Gloop from the directory the program is in. Why you would want to append the contents of .Profile to the PATH is beyond me. It's usually empty, so the effect would be nothing!

If you want to make your changes to the PATH environment variable persistent across reboots, put the export command, and everything else you need from the first line of this answer, and append it to the end of the file /home/<user>/.bashrc

.bashrc holds your personal bash environment. It is sourced each time you log in. Try taking another look at the video, and see what the author is trying to do with .Profile

Brian
  • 374