21

I've installed Linux subsystem for Windows 10. It works fine, but I want to change the default shell environment for the subsystem.

I did sudo apt-get install fish and then chsh -s /usr/bin/fish. But when I start bash.exe in Windows, it always starts the bash (I think it is predictable).

Does anyone know arguments to change this behavior?

2
  • When you start bash.exe you are obviously explicitly starting bash. I'm not familiar with the Linux subsystem in Windows 10, but I would expect there to be some way to start a "Linux" shell without explicitly starting one specific shell.
    – user
    Aug 7, 2016 at 19:25
  • Did you tried an ugly edition of your bashrc or bashprofile to re-route interactive bash calls to fish? Adding a line like isatty && exec fish may worth the try when you are totally out of actual solutions.
    – A. Loiseau
    Aug 7, 2016 at 22:52

9 Answers 9

9

You cannot change the default shell per se since the Linux subsystem is started via the bash.exe residing in the system directory.

You can, however, make a new shortcut like the one that already exists for bash and make it run the command

%systemroot%\system32\bash -c /usr/bin/fish

This way you will be running fish immediately.

5
  • 1
    I used %systemroot%\system32\bash.exe ~ -c /bin/zsh to make ZSH open in my home directory. Aug 11, 2016 at 20:13
  • Alternatively, set the "Start in" field in the shortcut to %userprofile% to start the shell in your home directory.
    – dOxxx
    Sep 29, 2016 at 2:07
  • @konqui This doesn’t break any other shell. It’s a new shortcut for starting it. Your bash will work just fine Nov 1, 2017 at 7:49
  • @SamiKuhmonen there wasn‘t anything said about a new shortcuts - i corrected it now i can life with this answer.
    – konqui
    Nov 1, 2017 at 7:54
  • 1
    While this was correct when written, it's now mostly wrong. First, the bash.exe way of starting WSL is now deprecated. When started with wsl (the replacement command), WSL will start with whatever shell is defined in /etc/passwd (the normal Linux method of selecting the user's shell). See @Mikhail's answer for the correct way to do this in "modern" WSL. Jul 25, 2022 at 16:38
26

When this question was originally asked, bash.exe was used to start WSL. However, this command is now listed as "deprecated" in the WSL documentation. If attempting to start via the deprecated bash.exe, command, the shell will always be (naturally) Bash. Other answers here (such as running a different shell via ~/.bashrc) or running with bash -c can be used, but they are less efficient and no longer recommended.

The replacement command for starting WSL is now wsl.exe, and since the Windows 10 Fall Creators Update, you can use the "normal" Linux chsh to set the default shell for your user.

For example, to set zsh as default shell:

chsh -s /bin/zsh

Then exit your existing shell and run (or restart) wsl.exe from command prompt.

Note that this has the same effect as (but is safer than) editing /etc/passwd directly as in some of the other answers.

9

Open bash, run nano ~/.bashrc and paste this in:

if [[ -t 1 && -x /usr/bin/zsh ]]; then
    exec /usr/bin/zsh
fi

Just change the shell to fish or whatever you want. The -x check is important if you ever re-install Bash -- you won't be able to open it after a fresh install because the exec command will fail and then Bash just closes.

If that happens, delete/rename your .bashrc file here:

C:\Users\<USERNAME>\AppData\Local\lxss\home\<USERNAME>\.bashrc

The -t I believe checks if stdout is open. Not sure why that's important, I copied it from this article.

1
2

To change the default shell for the Windows Subsystem for Linux

Open WSL, log in and type the following - after you entered the SUDO command it will request your password.

   sudo nano /etc/passwd

Scroll down the list and amend the line with your username - usually it's the last line in the list. e.g.

   username:x:1000:1000:,,,:/home/username:/bin/fish

Restart WSL after your edits, and you should be logging in with the shell of your choice.

As we're using Windows as the host operating system, we can also edit the passwd file by navigating to this location:

%LocalAppData%\Packages[Linux Distribution]\LocalState\rootfs\etc\passwd

Use a quality text editor like Notepad++ as it's capable of keeping Linux line break formatting.

Restarting the WSL will enable the edits.

This was based on @vvasch's answer.

2
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 29, 2022 at 13:38
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 29, 2022 at 18:10
0

I just edited /etc/passwd. Setting the default shell for my user to zsh. Works without problems.

vvasch:x:1000:1000:,,,:/home/vvasch:/bin/zsh
0

For example you can run fish from within the PowerShell after executing that one:

New-Item 'C:\Windows\System32\fish.bat' -ItemType File -Value 'ubuntu.exe run fish'
0

Open the passwd file and change your username shell line.

sudo vi /etc/passwd

pase:x:1000:1000:pase:/home/pase:/bin/bash

pase:x:1000:1000:pase:/home/pase:/bin/zsh

1
0

There's another way to link WSL Fish Shell to Windows Terminal by simply adding

"commandline": "wsl -e fish",
"startingDirectory": "."

into Ubuntu Section of your settings.json

0

If you want to use e.g. zsh as your shell, you can update $HOME/.bashrc to be the following. As others have noted, WSL Ubuntu is started via the bash command.

$HOME/.bashrc:

zsh
exit
3
  • 2
    Welcome to Ask Ubuntu! Just a heads-up that this is fairly wrong. First, you are basing this on an old, outdated answer -- WSL is no longer started with bash.exe. That's an officially deprecated command according to the docs, so expect it to be removed at some point in the future. The documented way to start WSL now is via the wsl.exe command, which uses the "normal" Linux way of choosing the shell (see @Mikhail's answer). Jul 25, 2022 at 16:36
  • 1
    @NotTheDr01ds - AskUbuntu? SuperUser... ;-) Jul 25, 2022 at 18:22
  • @Greenonline Oops! Jane - Welcome to Super User! Not the first time I've done that, and I'm sure I'll do it again, but twice (that I know of) in a few hundred comments probably ain't bad ;-) Jul 25, 2022 at 18:24

You must log in to answer this question.

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