I have recently started off with Linux, and am having some confusion with how to set something to PATH, I went through many wikis, but things aren’t getting cleared, like I wanted to know what is the difference between putting things into the .bashrc file and /etc/environment file, and do we put the directory paths into the .bashrc file only, or is there some other file which we can use to mention our environment variables?
>Solution :
Your options are: /etc/bashrc, /etcprofile, ~/.bashrc, ~/.profile`
The first two are generally not to be used as they are subject to change on system updates. If you must set global paths and environment (i.e. for every user) use /etc/bashrc.local or /etc/profile.local .
If you want to set env. variables for yourself/one user only then use ~/.bashrc or ~/.profile.
~/.profile is read for a login-shell only (according to the comments in mine:
# This file is read each time a login shell is started.
# All other interactive shells will only read .bashrc; this is particularly
# important for language settings, see below.
So shells you start by clicking on a Terminal icon will read ~/.bashrc.
As a rule I tend to put my global PATH modifications (i.e. for CUDA) into /etc/bashrc.local and anything that is only for me into ~/.bashrc.
Modifying PATH (and others) should be done by prepending to it via:
export PATH=<path>/<to>/<new SW binaries>:$PATH