wsl cannot access ubuntu path from command line

If gcc is in your WSL/Ubuntu path, but not showing up when you try to execute it via wsl gcc, then that's likely a manifestation of this. When executed with a command, WSL launches the shell as a non-login, non-interactive shell.

If you've modified the path inside .bash_profile, .bashrc, or any related file (depending on your shell), then you need to tell WSL to launch your shell with the proper flags to read those config files. Try:

wsl -e bash -lic "gcc"
  • -l for login shell
  • -i for interactive shell
  • -c to specify the command