DEV Community

Cover image for How to Install Oh My Zsh! on Windows 10 Home Edition
Vinícius Albuquerque
Vinícius Albuquerque

Posted on

How to Install Oh My Zsh! on Windows 10 Home Edition

As a developer, some tools may be a game changer for your productivity, but sometimes we just need to work in an environment that makes things easier for us.

If you're constantly making typos on commands, or everything being on the same color makes it difficult to see mistakes, it will not be a big deal when you analyze those mistakes alone. But in reality, those things pile up until you find it weird that you are so tired at the end of the day. And this happens because you are using a lot of your focus just to make sure everything is alright while you're working.

I this tutorial, I'll show you how to set up a terminal that makes things easier while working, so that you can focus on what is really important and stop wasting your energy on small things.

This is the result you should have at the end:

terminal pic

Warning: This tutorial is for people who are using Windows 10 Home Edition. It doesn't have Hyper-V, so the only way of having bash is via WSL1. If you have Hyper-V on your version, try installing WSL2. The rest of steps of the tutorial may be the same, though.

At the end, you will have:

  • An Oh My Zsh! terminal instance, with all the benefits it brings out of the box.
  • Spaceship Prompt theme applied, so that you have cool highlighting and signs that show the current state of the git repository you're in (if there are things changed that were not staged, staged but not committed, etc.).
  • Hyper as an alternative to open Oh My Zsh! with font ligature's feature.
  • Visual Studio Code shell integration, so that you can use it inside the IDE.
  • NVM and Node working on your terminal.

The Benefits

  • Automatic cd: Just type the name of the directory
  • Recursive path expansion: For example “/u/lo/b” expands to “/usr/local/bin”
  • Spelling correction and approximate completion: If you make a minor mistake typing a directory name, ZSH will fix it for you
  • Plugin and theme support: ZSH includes many different plugin frameworks

1. Activate "Windows for Linux Subsystem" Feature

  • Run this script on PowerShell:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  • Restart your machine.

2. Install a Linux Distribution

You shouldn't have problems in this step. Just open Microsoft Store App and search for a distro. In my case, I installed Debian.

3. Install Zsh

Open Debian from Start Menu. It will open a command prompt with the same features as Debian's terminal.

If you try to run sudo apt-get install zsh first, you may receive an error (Unable to locate package zsh). So, first you should run these two commands:

$ sudo apt-get update
$ sudo apt-get upgrade

Now you will be able to install Zsh properly, running:

$ sudo apt-get install zsh

When the installation is done, run this:

$ zsh

This will walk you through some basic configuration for zsh.

4. Install Oh My Zsh!

Install curl:

$ sudo apt-get install curl

Install Oh My Zsh!:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

While installing, it will ask if you want to set zsh as standard. Answer the prompt as you wish.

5. Set the theme Spaceship Prompt as default for Oh My Zsh!

Install Git:

sudo apt-get install git

Clone the theme's repository:

git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt"

Symlink spaceship.zsh-theme to your oh-my-zsh custom themes directory:

ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"

Now you must edit Zsh configuration file so that Oh My Zsh! uses this theme. If you already have Visual Studio Code installed, you can open the file using the code bellow:

code ~/.zshrc

Add this line at the end of your .zshrc file:

Set ZSH_THEME="spaceship"

SPACESHIP_PROMPT_ORDER=(
  user          # Username section
  dir           # Current directory section
  host          # Hostname section
  git           # Git section (git_branch + git_status)
  hg            # Mercurial section (hg_branch  + hg_status)
  exec_time     # Execution time
  line_sep      # Line break
  vi_mode       # Vi-mode indicator
  jobs          # Background jobs indicator
  exit_code     # Exit code section
  char          # Prompt character
)
SPACESHIP_USER_SHOW=always
SPACESHIP_PROMPT_ADD_NEWLINE=false
SPACESHIP_CHAR_SYMBOL="❯"
SPACESHIP_CHAR_SUFFIX=" "

Before going ahead, you need to install Fira Code font. Follow the instructions here.

6. Install Hyper Terminal

You must have noticed the terminal is kinda buggy right now. It seems the fonts do not load properly. So, we will install Hyper to solve that problem. It will give you a pleasant experience, supporting all Spaceship Theme's features.

Just go to https://hyper.is and click the big download button, at the right on your screen. Then open it and follow the instructions.

After that, open Hyper and its "Preferences" file (Ctrl + ,).

{
  ...
  // add Fira Code as first font in font family with optional fallbacks
  fontFamily: '"Fira Code", Menlo, "DejaVu Sans Mono", "Lucida Console", monospace',
  ...
  shell: 'C:\\Users\\<your-user-name>\\AppData\\Local\\Microsoft\\WindowsApps\\debian.exe',
  shellArgs: [],
  ...
}

Important: Change <your-user-name> to your username on Windows. If you have installed other Linux distribution, change shell path accordingly. I believe all distributions installed via Microsoft Store will be at the same place, but I don't know for sure.

Another important thing: Your shellArgs attribute must be an empty array, otherwise it will not work.

I like the theme Dracula for Hyper. If you wish that too, add this on the config file too:

plugins: [
  'hyper-dracula'
]

7. Add plugins to your terminal

Now we're going to add some cool features:

  • fast-syntax-highlighting: It adds syntax highlighting to your terminal, showing what typos you made;
  • zsh-autosuggestions: It suggests commands as you type based on history (commands you've used before) and completions;
  • zsh-completions: It adds thousands of completions for usual tools like Yarn, NVM, Node, etc, so that you need only to press TAB to complete the command.

Fetch and run zinit script:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma/zinit/master/doc/install.sh)"

Open zsh configuration file again:

code ~/.zshrc

Add this line at the end of your .zshrc file:

zinit light zdharma/fast-syntax-highlighting
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-completions

8. Set up Visual Studio Code shell integration

  • Open Visual Studio Code
  • Ctrl + Shift + p
  • Open settings JSON
  • Add this line (or change it, if it already exists):
"terminal.integrated.shell.windows": "C:\\Users\\<your-user-name>\\AppData\\Local\\Microsoft\\WindowsApps\\debian.exe",

Important: Remember to change <your-user-name> to your actual Windows user name.

9. Don't Forget to set up Node

Some things you have installed on Windows will work already, but you'll have to install node specifically on your distro. We will use NVM (Node Version Manager) to have more freedom, if sometime we need to downgrade the version used keeping the other ones.

First, we need to install the basic build tools for node-gyp.

To do that, run this on your terminal:

$ sudo apt-get install build-essential

Then you'll have to download and run the script for installing NVM:

Important: Before running this, check if it has the last version on the website (0.35.3).

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

After that, close the terminal and open it again.

Now, you'll add again some more settings to .zshrc file.

code ~/.zshrc

Paste this code at the end of the file:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

To load the changes you've just made, run

source ~/.zshrc

Now, finally, we're ready to install node's lastest LTS version:

$ nvm install --lts

Set this version as the version nvm should use as standard:

nvm use --lts

Conclusion

Phew!!! If you endured until the end, congratulations. It was surely a long ride for me.

I just want to highlight something before ending this article: The path structure for navigating folders is a little different.

If you want to go to C:\Users\MyUserName\Documents\awesome-repo, for example, you will use cd /mnt/c/Users/MyUserName/Documents/awesome-repo.

This means your drives are at /mnt/. From there, the path structure is pretty much the same.

I hope this was helpful to someone.

If something didn't work for you, or even if you have found a workaround for some specific problem, please leave a comment and I'll update this article as soon as possible. I'm sure it will help someone who passes by in the future.

Latest comments (59)

Collapse
 
affanthebest profile image
Siddiqui Affan

Thank you for the amazing article.
However when I open terminal, it does not open with current workspace folder.
Do have any solution for it?

Collapse
 
chaglr profile image
chaglr

Quite AMAZING !!!

Collapse
 
homestaymom profile image
HomeStayMom

Great step-by-step tutorial. Small comment : zinit changed location as of 1st July 2022 the correct code should be updated to
sh -c "$(curl -fsSL raw.githubusercontent.com/zdharma-..."

Collapse
 
homestaymom profile image
HomeStayMom

➜ ~ curl -o- raw.githubusercontent.com/nvm-sh/n... | bash
for some reason didn't work for me. thus I tried

~ export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion

➜ ~ export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
➜ ~ nvm

Collapse
 
aldorr profile image
Allan Dorr

Thanks Vinícius, this was very helpful.
One thing I would like to add, is making an alias in ~/.zshrc for VSCodium or VSCode, so you can open files from the command line.
For this I added:

alias code="/mnt/c/Program\ Files/VSCodium/VSCodium.exe"
Enter fullscreen mode Exit fullscreen mode

or you use your path to VS Code, wherever that is. I.e.:

alias code="/mnt/c/Users/{Username}/AppData/Local/Programs/Microsoft\ VS\ Code"
Enter fullscreen mode Exit fullscreen mode

This makes jumping back and forth a little easier.

Collapse
 
kamarguera profile image
Augusto Cesar Camargo

Can you help? at the end it is showing this:

➜ ~ source ~/.zshrc
/home/kamarguera/.zshrc:106: command not found: Set
/home/kamarguera/.zshrc:154: bad pattern: /home/kamarguera/.nvm/nvm.sh[
➜ ~

Collapse
 
kamarguera profile image
Augusto Cesar Camargo

Perhaps Zinit installation changed it's link?

sh -c "$(curl -fsSL git.io/zinit-install)"

I found this URL is this correct ?

I hope I did some help

Collapse
 
kamarguera profile image
Augusto Cesar Camargo

sh -c "$(curl -fsSL raw.githubusercontent.com/zdharma/..."

returning 404 error, can someone help?

Collapse
 
chrislfieldsii profile image
Christopher Fields

This article was a lifesaver for me being able to work on my gaming PC sometimes too. Before this, I just refused to develop on my windows machine unless absolutely necessary but now it is a bit more bearable

Collapse
 
masen666666 profile image
masen666666

For step 7, zinit light zdharma/fast-syntax-highlighting was changed into
zinit light zdharma-continuum/fast-syntax-highlighting

Collapse
 
kyokatarz profile image
Giang Tran • Edited

Hey thanks for instructive guide. I really like it. One thing I wanna ask tho, when I run zsh in VSC (it works), its default path is set to /home/. Adding cwd in VSC config crashes the terminal immediately.

Do you know how to set the zsh default path to project's path on terminal launch?

Collapse
 
thecomitre profile image
Bruno Comitre • Edited

Valeu amigo. Você é um amigo

Prova que nem todo herói usa capa

Collapse
 
rubengmurray profile image
Reece Daniels • Edited

A couple of things I found whilst walking through:

  • Step 1: Needed to run Powershell as Administrator (even though my windows account is an admin)

  • Step 4: Needed git installed before I could run sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

  • Step 7: Re-opening Hyper, I see /home/user/.zshrc:103: command not found: Set at the top of my terminal

  • Step 7: sh -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma/zinit/master/doc/install.sh)" returns a 404

  • Step 8: Adding the "terminal.integrated.shell.windows": "C:\\Users\\<your-user-name>\\AppData\\Local\\Microsoft\\WindowsApps\\debian.exe", into VS code returns the following error (seems to still work though)

This is deprecated, the new recommended way to configure your default shell is by creating a terminal profile in `#terminal.integrated.profiles.windows#` and setting its profile name as the default in `#terminal.integrated.defaultProfile.windows#`. This will currently take priority over the new profiles settings but that will change in the future.(2)
Enter fullscreen mode Exit fullscreen mode

Step 9: Appreciate the note on version of nvm - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash worked

Step 9: The following was already in my .zshrc after nvm install

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sim1029 profile image
Simon Schueller

For step 7 You should use this command instead

sh -c "$(curl -fsSL https://git.io/zinit-install)"

Collapse
 
omarkhangithub profile image
Omar Khan

When doing..
source ~/.zshrc

I get the error:
Command Not Found: set

I am unable to proceed :(

Collapse
 
sim1029 profile image
Simon Schueller

Can be fixed by setting ZSH_THEME="spaceship" instead of the default theme at the top of the ~/.zshrc

Collapse
 
rajdeepmondal1 profile image
Rajdeep Mondal

Thank you

Collapse
 
mauryarohit profile image
mauryarohit

Thanks for the article. Appreciate it so much.
However, if you follow the above mentioned Step 8 your terminal will not open with current workspace folder, to solve this follow these steps instead:

  1. Click Ctrl + Shift + P, search "Terminal: Select Default Profile" and select your Linux distro. Hope this helps too!!
Collapse
 
affanthebest profile image
Siddiqui Affan • Edited

It's still not not opening with current workspace folder