0

(Please excuse my English)

I installed WSL Ubuntu 24.04 on my Windows 11 pro machine, and edited /etc/environment like below to change the system-wide $PATH.

  • Before

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

  • After

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/mybin"

However, Only the root user' $PATH changed, and the default user's $PATH did not changed at all, like below. ('us' is the default username of WSL Ubuntu and 'SERVER' is my Windows machine name)

us@SERVER:~$ echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/snap/bin

us@SERVER:~$ su root

Password:

root@SERVER:/home/us# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/mybin

Considering that the default user's $PATH contains the string /usr/lib/wsl/lib, it seems that WSL Ubuntu sets the default user's $PATH somewhere else.

How can I modify the default user's $PATH in WSL Ubuntu?

3
  • I think the issue is that WSL skips any traditional login process, which is what would normally invoke the pam_env.so module to read /etc/environment - see Any idea why on WSL2 PAM modules are not loaded on login (for example pam_env)?. When you use su it goes through a normal PAM stack, per /etc/pam.d/su for example (and similar for sudo). Commented Apr 28 at 16:58
  • @steeldriver : I found that this is a very old and unresolved problem. bash not picking up /etc/environment Commented Apr 29 at 17:10
  • Good find - I didn't see that Commented Apr 29 at 17:10

1 Answer 1

0
  1. Which shell are you using? bash ?

    ps -o cmd= -p $$ 
  2. I'm not sure that /etc/environment (or rather /etc/environment.d/*.conf) is the best place to update your PATH environment variable. Did you try to update one of the following files instead?

  • ~/.profile (any shell, user-wide)
  • ~/.bash_profile (bash, user-wide) -- not always loaded, e.g. when adding a tab in a terminal.
  • ~/.bashrc (bash, user-wide) -- should always work
  • /etc/bash.bashrc (bash, system-wide)
  • /etc/profile (any shell, system-wide)
2
  • The default shell of WSL Ubuntu 24.04 is bash. I tried editing /etc/profile, and this time the default user's $PATH changed, but root's $PATH did not. Commented Apr 29 at 16:55
  • Check which shell is used by your root profile, then apply the aforementionned steps once you are identified as root. For example, you could update /root/.bash_profile or /root/.bashrc (as ~ corresponds to ~root which corresponds to /root). Commented Apr 30 at 11:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.