Where to put the assignment of global environment variables

Oliver Grawert ogra at ubuntu.com
Thu Sep 15 08:40:42 UTC 2022


hi,
Am Donnerstag, dem 15.09.2022 um 08:54 +0200 schrieb Volker Wysk:
> Am Dienstag, dem 13.09.2022 um 19:42 +0200 schrieb Oliver Grawert:
> > hi,
> > Am Dienstag, dem 13.09.2022 um 16:01 +0200 schrieb Volker Wysk:
> > 
> > > looks more like a system wide thing.
> > 
> > right, and this is what you normally set in /etc/environment, which
> > is
> > the systems "environment for global variables read during boot" 
> > (i guess this is why peter calls it the "boot environment" :) ) ...
> > 
> > so adding your snippets to /etc/environment.d/ is the exact right
> > thing
> > here to do ... 
> 
> So, when I have something like
> "PATH=$PATH:/usr/local/lib/mercury.../bin"
> in there, will the "$PATH" be expanded - or will I have "$PATH"
> instead of
> "/bin:/usr/bin:/sbin:...", and the system won't be able to boot any
> longer
> ..?

if you put it properly into an /etc/environment.d file, it will be
processed after the /etc/environment file (which you should not edit)
... that file contains the PATH your OS installer created and the PATH
variable from there will already be set when your file snippet in the
.d directory is processed ... so if all done properly like above (i.e
with "PATH=$PATH:/usr/local...", your PATH will just be enhanced with
the additions you put in there.

> 
> > and indeed, this environment applies to the whole system, which
> > includes your services and daemons, so it is only read on boot
> > pretty
> > much as the very first thing when switching from the initrd to the
> > rootfs ... 
> 
> Read on boot by a shell (as a shell script), or how will it be
> interpreted?

by /sbin/init usually (which is systemd in recent ubuntus), if it would
be interpreted by a shell only, it would also only apply to that
specific shell (but for this you have /etc/profile (and the respective
.d directory and should not use /etc/environment). /sbin/init sets the
variables globally, so services, GUI apps and other executables can use
them even when not started from inside a shell.

ciao
	oli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20220915/e84fcc4c/attachment.sig>


More information about the ubuntu-users mailing list