0

In windows, I use the Rapid Environment Editor. It's wonderful and shows me the system and user environment variables broken down into individual entries. Is there such an animal for LINUX? I am so confused by all the places PATH entries can exist -

~/.profile
/root/.profile
~/.bash_profile, 
~/bash.bashrc, 
~/.bashrc, ~/.profile, 
/etc/bash.bashrc
/etc/skel/.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel/dot.bashrc
/usr/share/base-files/dot.bashrc
/home/stefan/.bashrc
/root/.bashrc

I have read that that ~/.bash_rc is not read by any program, and ~/.bashrc is the configuration file of interactive instances of bash. I should not define environment variables in ~/.bashrc. The right place to define environment variables such as PATH is ~/.profile (or ~/.bash_profile)

I am trying to add the PATHs for luarocks and the LUA_PATH for same.

So the PATH is not just for the terminal to read so it knows where to look for commands that I enter there. Rather, it seems OTHER programs ALSO use the PATH for their own nefarious purposes. That seems like a security risk BTW and I wonder if certain files containing the PATH variable have different priviledges than others. So for example, if I want a program other than terminal to execute a certain linux program, then I want it to look in only less secure locations.

aquagremlin
  • 3,131
  • 2
  • 19
  • 42
  • 3
    There isn't a single place to set environment variables in Linux, so such a tool isn't even possible to implement in an authoritative manner; every distro -- and, perhaps even every individual machine, if its admins customize the init scripts -- can source different locations, and thus have different environment variables set at login time. (And then there are _other_ sources of environment variables -- PAM modules, sudo configuration, etc). – Charles Duffy Mar 30 '15 at 17:19
  • 1
    BTW, `/etc/skel` contains contents that are copied to new users' home directories, so `/etc/skel/.bashrc` provides the *default* .bashrc for new users, not the one that's actually used for any given user. But environment variables shouldn't be getting set in `.bashrc` at all; they belong more properly in `.profile` and its kin (potentially including `.bash_profile`). – Charles Duffy Mar 30 '15 at 17:22
  • 1
    That list has exact duplicate entries (`~/.profile` twice), entries that are the same as other entries when expanded (`~/.bashrc`, `/home/stefan/.bashrc`, and `/root/.bashrc` depending on if you are the `stefan` user or `root`) and entries that aren't used for this purpose but are instead either documentation examples (`/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc`) defaults for new users (`/etc/skel/.bashrc` as CharlesDuffy indicated) and common temporary/etc. names but not read by anything (`~/bash.bashrc`) and so is more confusing then necessary. – Etan Reisner Mar 30 '15 at 17:30
  • Each distro has their own *idealized* method for modifying and defining new environment variables. – Ignacio Vazquez-Abrams Mar 30 '15 at 17:49
  • If you only want to view $PATH in individual lines: `echo "${PATH//:/$'\n'}"` – Cyrus Mar 30 '15 at 18:23
  • Maybe this answer will help http://stackoverflow.com/a/26962251/450989 – Grzegorz Żur Mar 30 '15 at 19:14

1 Answers1

1

The way I deal with the PATH is first I have a file ~/path.conf

/home/bin
/usr/local/bin
/usr/bin

Then I add this to ~/.bashrc

PATH=$(awk '{printf b++ ? ":"$0 : $0}' ~/path.conf)

Example

Steven Penny
  • 82,115
  • 47
  • 308
  • 348