The
/etc/environmentfile normally contains only this line:PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"It sets the
PATHvariable for all users on the system to this default value, which should not be changed in a major way. At least you should not remove any of the important paths like/bin,/sbin,/usr/binand/usr/sbinfrom it.This file is read as one of the first configuration files by every shell of every user. Note that it is not a shell script. It is just a configuration file that gets parsed somehow and that may only contain environment variable assignments!
The
~/.profilefile can contain many things, by default it contains amongst other stuff a check whether a~/bindirectory exists and adds that to the user's existingPATHvariable, like this (on older Ubuntu releases prior to 16.04 - newer releases add- which adds it unconditionally -- and on 18.04, which also adds "~/.local/bin"):# set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fiYou see that the old value of
PATHgets reused here and the new path is only appended to the beginning instead of overwriting everything. When you manually want to add new paths, you should also always keep the old$PATHvalue somewhere in the new string.This initialization script is read only by the shells of the user to which it belongs, but there's another condition:
# ~/.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 if you use the default Bash shell, you should make sure that you don't have a
~/.bash_profileor~/.bash_loginif you want the changes in~/.profileto have an effect for your user.
further info on how user's local bin directories are added to PATH on 18.04