Search code examples
windows-subsystem-for-linuxfish

Set $path fail (win10 subsystem linux, ubuntu, fish shell, brew)


Environment

  • OS: Windows Subsystem for Linux, Ubuntu 18.04
  • shell: fish
  • Tool kit management: brew (homebrew/linuxbrew)
    • fish had installed
      • fish had set as default shell
    • brew had installed
      • brew environment setting as official site
      • php had installed with brew
      • composer had installed with brew

target

I want to use PHP with "php" command which brew had installed but fail.

What I had done

  • I try to set environment by myself

    • Following success in current shell but fail when restart shell
    # in bash I tried these
    PATH=${PATH}:/home/linuxbrew/.linuxbrew/bin/
    export PATH=${PATH}:/home/linuxbrew/.linuxbrew/bin/
    
    # in fish bash I tried these
    set PATH $PATH /home/linuxbrew/.linuxbrew/bin/     <-update: updated
    export PATH $PATH:/home/linuxbrew/.linuxbrew/bin/  <-update: wrong
    
    • Following success in bash but fail in fish
      • add the command above in .bashrc file in user directory (.bashrc seems only run when bash)
    • Following should success but fail
      • sudo -H vi /etc/environment
      • add /home/linuxbrew/.linuxbrew/bin/ in it

Solution

  • If you want commands to run when starting fish, you need to put them into a file called "config.fish" in ~/.config/fish/. Bashrc is, as the name implies, specific to bash.

    Also "export" is used to mark a variable for "exporting", meaning passing it on to external commands the shell starts. $PATH is usually inherited from whatever starts the shell, which then means it's exported anyway, so your export line is useless.

    Also your fish command needs a slight adjustment:

    set PATH $PATH /home/linuxbrew/.linuxbrew/bin/
    

    $PATH in fish is a list, and so it needs to be set as multiple arguments, not one string. In fish 3.0 (which was released after Ubuntu 18.04) this was adjusted to automatically split on ":", but even in that case you'll have to quote it or it will have surprising results.