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.

3
  • 2
    what is the question? Why should /etc/environment be executable? It is not for 20.04 and probably should not be.
    – pLumo
    Commented May 19, 2022 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. Commented May 19, 2022 at 14:54
  • @steeldriver: Good information, but alas, the PATH wasn't set either after a fresh login. I change the question accordingly. Commented May 19, 2022 at 16:01

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .