DEV Community

loading...
Cover image for Installing ZSH on Windows

Installing ZSH on Windows

zinox9 profile image Arjun Porwal ・7 min read

Welcome Everyone

All of us have seen customizable and feature-full terminals in linux and mac,
if you want to have a cool looking & powerful terminal in windows too, Follow me!

Today I will be sharing how to install Z Shell with oh-my-zsh and also customizing it with an Awesome Theme and Plugins to bring a pimp to your terminal

This is how the Final Setup will look like : 😎

Preview

This post is divided into 4 Parts

  1. Setting Up Windows for ZSH installation (Cygwin & Cmder)
  2. Installing Oh-my-zsh
  3. Customizing Terminal and ZSH with Color Schemes & Themes
  4. Some Extras to Refer to, Or some errors that might come.

You can refer to My Github Repo, to get the files and skip this process , to get the same terminal as mine & to get some useful resources instantly too.

So Let's Begin 😋


1. Setting Up Windows

  • For Windows we have to install

    a. Cygwin = Brings Unix environment in windows

    b. Cmder = One of the most Feature Full and customizable command prompt


a. Cygwin Setup

  1. Download Cygwin
  2. When Running The Installer, Follow the Instructions.
    1. Make Sure to Let the installer install at C:\cygwin64 Cygwin Setup
    2. For Download site Select Any URL , Click Add
    3. Stop at packages screen, search wget expand All under Web select latest version of it under bin of wget no need to select Source. Then Continue. Cygwin wget Screen
  3. Finish Installing and launch the Terminal.
  4. We are going to use Cygwin to Install Some Packages that will help to use Linux System on Windows. We will install apt-cyg which will work like apt-get and also install many other packages too like vim
    • Run The following to download apt-cyg with wget. Note you can prompt to install gdb, vim or dos2unix if you want to use them or just remove them, you can install even more packages of your choice if you wish !
     > wget rawgit.com/transcode-open/apt-cyg/master/apt-cyg

     > install apt-cyg /bin

     > apt-cyg install zsh git gdb dos2unix openssh vim [or your favorite text editor]
  • If you want your home folder to be your user's folder, you need to edit cygwin64/etc/nsswitch.conf. You can do this in the text editor you just downloaded, or type explorer /etc to open the root directory to edit the file.
    • Add this line to the bottom: db_home: windows

That's it for Cygwin , you can close the Terminal. Now let's move to the terminal we are using in this guide.


b. CMDER setup

This Might Feel a lot, but just stick with me and I will guide you through every step 😊.

In case you dont want to go through these , you can go to My Github Repo and just paste the specific files

Cmder Preview

  1. Download and install one font from the package of Powerline Font to use in the terminal for the custom Icons. For This Guide I will be using MesloGS NF patched for powerlevel10k theme, you can find it in my github.

  2. Download Cmder (the full Version !) it's a portable package so to install it just extract it into a folder where it can stay permanently. (Don't Paste in Program Files)

  3. Run cmder.exe

  4. Right Click the Tab Bar and open Settings, We will be tweaking some of it. You can read and make changes as you wish 👍

    i. Under General>Fonts. = Select Main Console Font MesloGS NF and remove check from Alternative Font

    ii. Under General>Size & Pos. = Check Snap To desktop edges

    iii. Under General>Appearance. =

    • You can remove Check from Show Button In tab bar and Show Search Field
    • Select Hide Scroll Bar

    iv. Under General>Tab bar select auto show.

    v. Under General>Confirm You can switch off confirmation of creating new tab if you don't need it (I Never wanted it).

    vi. Under General>Taskbar

    • check Don't show ConEmu Window on taskbar &
    • Auto Minimize to TSA (to not interrupt in alt+tab)

    vii. IMPORTANT : Under Startup>Tasks

    Cmder Settings

    • Click on + then Rename it from Group xx to cygwin:ZSH.
      • Check Default Task For New Console
      • Under Task you can give Location of any Icon You Wish to have (.ico file), I have given one nice icon in my github
        -icon "C:\cygwin64\Cygwin.ico"
        
      • Now In the Last Command Box paste this command
        C:\cygwin64\bin\mintty.exe /usr/bin/zsh --login -i -new_console:d:%USERPROFILE%
        
      • Last step is Click on General and choose startup task from the dropdown {cygwin:ZSH}
      • Do the same for Admin Privileges , rename it as {cygwin:ZSH as Admin} and replace command with
        *C:\cygwin64\bin\mintty.exe /usr/bin/zsh --login -i -new_console:d:%USERPROFILE%
        

    viii. Under Features>Colors choose Monokai Scheme

    ix. For the setup of shortcuts, Click on Keys & Macro then change the shortcuts. Here is my setup :
    Win + Esc : Minimize/Restore
    Win + Down : Create New Console
    Win + T : Create new console (With Dialog)
    Win + N : Split: Duplicate active ‘shell’ split to bottom
    Win + Right : Switch Next Console
    Win + Left : Switch Previous Console
    Win + Q : Close active Console
    Win + E : Close all Consoles
    Win + Alt + P : Show Settings
    Win + Alt + Space : Show ConEmu Menu

    • To make These Work go to Keys & Macro>Keyboard and check Support Special Keys

    x. Under Keys & Macro>Paste make sure Multi Lines is Checked Everywhere.

    Finally. After Completing the Settings Click On Save Settings.

  5. You now Have setup to use Cygwin in Cmder, Close the terminal and open a new one

  6. Tada! you will see some differences, There You Go Running Cygwin In Cmder Successfully.

  7. If a Prompt Comes type 0 to exit, we can edit the specified files later manually.


2. Setting Up Oh-my-zsh

Now let's add a manager to handle plugins, updating and themes. It's Awesome that you have reached soo far, we are very close to completion. Great Work 🤘

  • Install oh-my-zsh the manual way, Run the lines one by one
> git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
> cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
  • Now Close the Terminal with shortcut (Win+q) or normal way, then open a new one
  • If it prompts , type 0 to exit

ZSH Installed

There You Go Running ZSH on WINDOWS !

Now we are going to install an awesom theme and edit all features of zsh and cygwin you can continue if you wish to make it look like mine.

You can also visit My Github Repo to instantly paste the files and you will be good to go !


3. Customizing Cygwin & Oh-my-zsh

  • Changing Color Scheme and other Mintty settings

    1. Right click your terminal
    2. Hit options
    3. Change font-size and Apply the settings , this creates .minttyrc file
    4. Browse to Root folder of the user , open .minttyrc file and paste my settings, to change the color scheme to mine
    BoldAsFont=no
    RightClickAction=paste
    Font=MesloLGS NF
    FontHeight=12
    Term=xterm-256color
    BoldAsColour=yes
    ConfirmExit=no
    Scrollbar=none
    Transparency=medium
    OpaqueWhenFocused=yes
    SelectionShowSize=1

    BackgroundColour=14,14,14
    ForegroundColour=228,228,228
    CursorColour=228,228,228
    Black=40,40,40
    BoldBlack=107,107,107
    Red=255,43,28
    BoldRed=243,91,80
    Green=2,192,97
    BoldGreen=0,253,127
    Yellow=251,188,46
    BoldYellow=253,197,86
    Blue=0,126,180
    BoldBlue=0,179,255
    Magenta=255,0,194
    BoldMagenta=239,133,214
    Cyan=87,208,249
    BoldCyan=141,219,245
    White=207,207,207
    BoldWhite=255,255,255
  • Changing Zsh Themes and prompts

    • To install the Powerlevel10k theme that I am using you can run
      
      git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
      
    • Set ZSH_THEME="powerlevel10k/powerlevel10k" in ~/.zshrc.
    • Close and Open a new terminal window
    • Finally Go through the setup in the prompt as you wish
    • I have edited the p10k.zsh file, manually to make it look even more clear, the file is available in My Github Repo 😉

  • Adding Plugins

    • To install plugins just go to your root user folder, open .zshrc and you will find a variable plugins. Simply add the plugins you want to install with spaces plugins=(git z zsh-autosuggestions)
    • Z = saves the locations you visit the most, so that you can access it in one shot
    • git = brings many aliases in the command line
    • npm Trash-cli = it is an npm package, very useful to replace rm command
    • Auto suggestions = automatically suggests the code to type and autocomplete, has to be installed manually not internally available
      1. run git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
      2. add zsh-autosuggestions in plugins variable

SETUP COMPLETE 🎉

Final Setup

There you go your Terminal has now become very powerful and awesome, it was great to share this with you all. Have Fun ! Keep Coding and Keep Exploring ! 🤘


Extras

  • You can checkout about all the features of oh-my-zsh on the internet , go explore
  • Errors :
    • on some commands oh-my-zsh runs less command with -R (repaint). You can disable this behavior by adding the following line at the end of your ~/.zshrc
    unset LESS;
  • This is set to -R in ~/.oh-my-zsh/lib/misc.zsh

  • incase there is Insecure completion-dependent directories error : run this

    chmod -R 755 ~/.oh-my-zsh

Discussion (29)

pic
Editor guide
Collapse
mburszley profile image
Maximilian Burszley • Edited

I'm uncertain why you'd go through the trouble of using cygwin/cmder when you can use WSL2+Terminal and have a native experience.

Collapse
zinox9 profile image
Arjun Porwal Author • Edited

Let me help you through this , I have specific reasons for not using WSL
Reason 1 - I will have to install Full linux shell in my windows
Reason 2 - The setup and usage of WSL was not easy to understand
Conclusion I simply preferred this way , cause I found it easier and I didn't have to install full linux shell in windows for just oh-my-zsh. Though If anyone does want a full native experience they can prefer WSL way too.

Collapse
mburszley profile image
Maximilian Burszley

Let me help you through this

I don't know if English is your first language, but that phrase is extremely condescending.

Reason 1 - I will have to install Full linux shell in my windows

You're already doing that with Cygwin.

Reason 2 - The setup and usage of WSL was not easy to understand

It's a Windows feature and then you install a distro through the Store. You're doing way more work in your post than what it takes to get it set up otherwise.

Thread Thread
zinox9 profile image
Arjun Porwal Author • Edited

I didn't mean the phrase that way, its all cool.
Ohkay so , with the help of Cygwin I am just installing apt-cyg , to install zsh & git that's all. The other packages are user's choice. But For WSL I have to go to windows store and install Full Ubuntu Shell Package .
Yes WSL is a windows feature, and some people might find it easier to set it up for their usage, I agree with that. It's just a matter of choice , for me it was easier to Find and Do it this way , and just shared it with others.
As I said Before, If anyone wants they can prefer going WSL way, this way isn't a compulsory.
Though thanks for listing this other way too here, it can help many more people 😊🤘

Collapse
hawtre profile image
hawtre

What do you mean by full Linux shell? You'd have to install zsh regardless, no?

Thread Thread
zinox9 profile image
Arjun Porwal Author • Edited

By Full Linux Shell I mean that , for the WSL way I will have to install Full Ubuntu Package (or whichever distro you prefer) just to use ZSH, in this way I am just installing apt-cyg package and then zsh that's it.
It's as simple as that and a matter of choice for the user, not a compulsory to go my way only. Just sharing what I found.

Collapse
jckodel profile image
J.C.Ködel • Edited

Working fine on Windows Terminal and VSCode, with some issues:

1) Flutter script only recognize MINGW, so you need to set an alias in your .zshrc: alias dart="/cygdrive/c/flutter/bin/dart.bat" and alias flutter="/cygdrive/c/flutter/bin/flutter.bat".

2) Git from cygwin doesn't work on flutter, so either don't install it or install git for windows and then delete (or rename) \cygwin\bin\git.exe

3) For Windows Terminal, open settings and change your prompt settings to "commandline": "zsh --login -i" (the default profile is {0caa0dad-35be-5f56-a8ff-afceeeaa6101})

4) For VSCode, configure your terminal to cygwin: "terminal.integrated.shell.windows": "C:\\cygwin64\\Cygwin.bat",, then edit that batch file to set zsh as the default shell: cd /d "%~dp0bin" && zsh --login -i

And that's it... zsh working fine on both Windows Terminal and VSCode, without that trashy WSL.

Collapse
muhimen123 profile image
Muhimen

Hey, it's giving no result for wget. what shall I do?

Collapse
zinox9 profile image
Arjun Porwal Author

Let me List some things that you might have missed :

  1. During installation the server that you selected , try another one.
  2. In the search check your spelling (reference to the snapshot I Provided)
  3. If there are any dropdowns visible try opening them and finding wget. Hope any of these helps. If it doesn't you can attach any of the Snapshot of your screen for me to help you more.
Collapse
muhimen123 profile image
Muhimen

Thanks bro. I just fixed it.

Thread Thread
zinox9 profile image
Arjun Porwal Author

Awesome ! 🤘

Collapse
ajinkyax profile image
Ajinkya Borade

thanks for this great article. But sadly after doing the zsh install step and quiting the cygwin terminal. When I reopen, there is no difference. no ZSH !

screenshot

Collapse
ngotienthien profile image
ngotienthien

how i change start directory when i open in contextmeu

Collapse
zinox9 profile image
Arjun Porwal Author

tried my best , but could not find a working way 😅

Collapse
olegkhodakivskyi profile image
OlegKhodakivskyi • Edited

Hi.
After commands
install apt-cyg /bin
and
apt-cyg install zsh git gdb dos2unix openssh vim

  • nothing happends, its should be like that?
Collapse
zinox9 profile image
Arjun Porwal Author

maybe waiting for sometime would have made it work , or else you can try the next steps and see if the commands worked properly. If the commands didn't work then you will not see the screen in cmder as I did. Good luck

Collapse
olegkhodakivskyi profile image
OlegKhodakivskyi

Ok, I got an issue. After this step: "Do the same for Admin Privileges , rename it as {cygwin:ZSH as Admin} and replace command with:...". I launch Cmder again, it's starting mintty.exe but after gave error: "/usr/bin/zsh: Exit 126.
Failed to run '/usr/bin/zsh': No such file or directory".
zsh folder was not in archive so I created one, but error still pop out. Any suggetions or info about it?

Thread Thread
zinox9 profile image
Arjun Porwal Author

Yeah so now its confirmed that the commands
install apt-cyg /bin
and
apt-cyg install zsh git gdb dos2unix openssh vim

did not work properly , that's why zsh is not installed yet. I think you can try to remove everything and follow the steps again. Maybe you missed a step that would have caused this problem.

Collapse
nvlinh99 profile image
Linh Nguyen Vu

How to set Cmder to default terminal of VSCode bro ?

Collapse
zinox9 profile image
Arjun Porwal Author

You can do it in VSCode using these commands in settings.json

   "terminal.integrated.shell.windows": "C:\\Users\\Username\\Cmder\\Cmder.exe",
   "terminal.external.windowsExec": "C:\\Users\\Username\Cmder\\Cmder.exe",
Enter fullscreen mode Exit fullscreen mode

replace the path to cmder with yours ,
even if you set it , it wont run as inbuilt terminal in VSCode , it is only possible to launch it externally.

Collapse
nvlinh99 profile image
Linh Nguyen Vu

Thanks bro.

Thread Thread
fl4zher profile image
Harun Kilic • Edited

It is actually possible with those lines in settings.json in VScode:

    "terminal.external.windowsExec": "C:\\Cmder\\Cmder.exe",
    "terminal.integrated.shell.windows":   "C:\\Cygwin64\\bin\\bash.exe",
    "terminal.integrated.shellArgs.windows": ["-lic", "cd $OLDPWD; exec zsh"]
Collapse
paras594 profile image
Paras 🧙‍♂️

great post !!! 👏👏👏🎉🎉

Collapse
zinox9 profile image
Collapse
nikosdev profile image
Nikos Kanakis

I will definetely try it !!!

Collapse
zinox9 profile image
Arjun Porwal Author

Hope You find it Awesome and Easy ! 🤘

Collapse
soadtech profile image
Fernando Ropero

Customizing Cygwin & Oh-my-zsh
step four is not clear to me, I don't know what to do, I can't find any files .minttyrc

Collapse
tranquyen profile image
Đặng Trần Quyền

How can we emmed this to Visual Studio Code ?

Collapse
axselll profile image
Axsel Riando S

i can't do a command like 'cd' anyone have the same issue?