0

I came across this issue as I wanted to extend the PATH variable for all users by adding another directory at the end of PATH in /etc/environment.

Neither opening a new shell nor a fresh login did show the extended PATH.

I found that the protections on /etc/environment were set to

-rw-r--r-- 1 root root 588 May 13 12:08 /etc/environment

Setting /etc/environment to be executable fixed this for me.

  • 2
    what is the question? Why should /etc/environment be executable? It is not for 20.04 and probably should not be. – pLumo May 19 '22 at 14:45
  • @pLumo Understanding this is the question. And understanding why my apparent "fix" is probably wrong. And the follow-up problem is how to extend the PATH for all users when adding it to /etc/environment does not work, but this is another question. – Sir Cornflakes May 19 '22 at 14:54
  • @steeldriver: Good information, but alas, the PATH wasn't set either after a fresh login. I change the question accordingly. – Sir Cornflakes May 19 '22 at 16:01

1 Answers1

6

The file /etc/environment is not intended to be executed as a program but read or sourced so it does not need the executable privilege and should not have one.

For interactive shells the file should normally be read by the PAM system. For example on Ubuntu 22.04 in WSL2 it should be read by login and sshd. Check the files in /etc/pam.d/. If you did not test login on the text console or over SSH, test it.

Better way of changing the environment variables for all users is adding an .sh file to /etc/profile.d/. This way you can separate your configuration from the distribution's system files and prevent possible problems during upgrades.

Some more details are in this question: Setting PATH variable in /etc/environment vs .profile