How to change the default shell in Cygwin?

27,572

Solution 1

The answer depends on how you start Cygwin.

If you start Cygwin with Cygwin.bat, modify the last line of /Cygwin.bat (usually C:\cygwin\ or C:\cygwin64\).

If you start Cygwin with mintty, then add the shell as a parameter: mintty /usr/bin/zsh -

Solution 2

If you run mintty.exe directly or run Cygwin Terminal from the start menu or desktop (which is a shortcut to mintty.exe), you can set the SHELL environment variable in Windows to /usr/bin/zsh.

On Windows 7:

  1. Press Windows key.
  2. Start typing "environment".
  3. When it appears, select "Edit environment variables for your account".

The rest should be self-explanatory.

Solution 3

Copied from my answer on Stack Overflow:


Instead of creating a passwd file, which Cygwin recommends against1, you could edit /etc/nsswitch.conf. Add or edit the following line:

db_shell: /usr/bin/fish

The down/up side of this method is that, if you have multiple users, this change affects all of them. The up/up side is that it's dead simple. The only catch is that you have to restart Cygwin.

If you do use mkpasswd after this change, it will use your new default shell for all users that are allowed to log on.


1 The mkpasswd documentation says this:

Don't use this command to generate a local /etc/passwd file, unless you really need one. See the Cygwin User's Guide for more information.

I can't really find any solid reasoning in the user's guide, other than a mention that you'll have to regenerate the /etc/passwd and /etc/group files if your users and groups change, which I suppose is a decent enough reason. I can say that the process is somewhat error prone for newbies.

Solution 4

This is a hack: put this as the first line of your ~/.bash_profile:

exec zsh
Share:
27,572

Related videos on Youtube

gyaani_guy
Author by

gyaani_guy

Updated on September 18, 2022

Comments

  • gyaani_guy
    gyaani_guy over 1 year

    I am trying to change my default shell from bash to zsh in cygwin.

    1. The normal unix command chsh isn't available on cygwin
    2. The etc/passwd file it seems isn't used anymore in existing versions of cygwin.

    So how else can the default shell be changed ?

  • gyaani_guy
    gyaani_guy almost 9 years
    Thank you, I am using Conemu. Had to change the sh.exe to zsh.exe in Conemu Settings > startup > tasks > bash Cygwin Bash > set CHERE_INVOKING=1 & %ConEmuDrive%\CygWin\bin\sh.exe --login -i
  • deed02392
    deed02392 over 7 years
    @gyaani_guy I am just using ConEmu to execute CygWin\bin\zsh.exe. sh.exe --login will launch Bash, how do you change that? Or does it not matter anyway? I imagine sh.exe --login is unnecessarily executing sh before zsh...
  • gyaani_guy
    gyaani_guy over 7 years
    @deed02392 I am not sure I understand.. but the exact command I am using is set CHERE_INVOKING=1 & %ConEmuDrive%\CygWin\bin\zsh.exe --login -i hth
  • deed02392
    deed02392 over 7 years
    @gyaani_guy thanks, I was confused because in your first comment you seemed to imply that you start zsh with sh.exe. Now I realise I just didn't read your message correctly :-)
  • Morgan May
    Morgan May over 7 years
    The mintty example didn't quite work for me. It had issues until I made it a login shell by adding -l: mintty.exe -i /Cygwin-Terminal.ico /usr/bin/zsh -l -
  • Kevin Mills
    Kevin Mills about 7 years
    This seriously needs more up-votes. I've never seen this documented anywhere, and it's obviously the intended method.
  • David C.
    David C. about 7 years
    For those who don't want to rely on search to find the appropriate panel, right-click the Start menu and select "System" to launch the System control panel. Then click "Advanced system settings" from the left-side column. On the "System Properties" window that pops up, click "Environment Variables..." to launch the environment variable editor.
  • bkunzi01
    bkunzi01 almost 7 years
    Worked perfectly!
  • user744403
    user744403 about 5 years
    See this answer for a better solution.
  • mtraceur
    mtraceur almost 5 years
    This is the only answer that directly allows you to directly pass the -l flag to zsh, so this is the only answer that allows you to have a proper login zsh instance started.
  • kohane15
    kohane15 about 3 years
    Exactly what I needed. Thank you!
  • zzapper
    zzapper over 2 years
    Choose 'User Variables for xxxx'. Then Add New Variable, Name SHELL, Value /usr/bin/zsh . Launch a new Mintty Window and you start in zsh .. no need to restart windows
  • choseph
    choseph about 2 years
    This does appear to be the slickest way to specify the desired Cygwin shell. Is it documented? Couldn't find it searching the cygwin site.
  • dc46and2
    dc46and2 about 2 years
    It's a documented feature of mintty. See mintty.github.io/mintty.1.html. There are other ways to get to the Cygwin terminal, without using mintty, so this is not a universal solution.