How to Install Oh My Zsh! on Windows 10 Home Edition
Tags: zsh, terminal, git, vscode
Published: 2020-06-20 19:31:16

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](https://i.imgur.com/Xck61P4.png)


> **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](#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:

```bat
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:

```bash
$ sudo apt-get update
$ sudo apt-get upgrade
```

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

```bash
$ sudo apt-get install zsh
```

When the installation is done, run this:

```bash
$ zsh
```

This will walk you through some basic configuration for zsh.


# 4. Install Oh My Zsh!

Install `curl`:

```bash
$ sudo apt-get install curl
```

Install Oh My Zsh!:

```bash
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:

```bash
sudo apt-get install git
```

Clone the theme's repository:

```bash
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:

```bash
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:

```bash
code ~/.zshrc
```

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

```text
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](https://github.com/tonsky/FiraCode/wiki/Installing#windows).

# 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 + ,`).

```json
{
  ...
  // 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:

```json
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:

```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma/zinit/master/doc/install.sh)"
```
Open zsh configuration file again:

```bash
code ~/.zshrc
```

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

```text
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):

```json
"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:

```bash
$ 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).

```bash
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.

```bash
code ~/.zshrc
```

Paste this code at the end of the file:

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

To load the changes you've just made, run

```bash
source ~/.zshrc
```	
		
Now, finally, we're ready to install node's lastest LTS version:

```bash
$ nvm install --lts
```

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

```bash
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.