2. WSL and ZSH Setup
Installing WSL and ZSH on Windows 10 ¶
- Open Powershell as admin and run the command below:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
If you are prompted to restart, press Y to confirm. You can do it at your convenience but it should be done before proceeding to the next step.
2.a Press start and go to the Microsoft Store. Search for Ubuntu and install it.
2.b If you experience any issue to install Ubuntu from the Microsoft Store (e.g. administrative restrictions), follow this README.md for a manual installation guide.
-
Open CMD/Powershell and type
ubuntu(orwsl) and press enter to see if it's properly installed. If successfully installed, you should see a bash prompt. You should also be asked to create a username and password. This will be used for your Ubuntu envinronment. Don't add any spaces for username. -
Run the command below to install ZSH.
sudo apt-get update # Updates all installed packages and their dependencies
sudo apt-get install zsh #Installs ZSH
NOTE: APT stands for Advanced Package Tool and is the equivalent of Windows Installer
- Run the command below to install ohmyzsh.
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
- Run the command below to create a zsh config file from the default ohmyzsh template.
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
Tip: Here's a full sample you can refer to, or use as-is, if you wish.
-
Type
zshto load ZSH, and thensource ~/.zshrcto load the default zsh configuration file. -
Run
nano ~/.zshrcto edit the config file in nano editor (CLI text editor) and change the theme/plugins/aliases as required. You can also runcode ~/.zshrcto edit the config file in VS Code. Create your first 2 aliases for editing and reloading the zsh config file:
alias editzsh="code ~/.zshrc" #Open config file in VS Code
alias reloadzsh="source ~/.zshrc" #Reloads latest config file in the shell
Now the next time you need to edit the config file, just type editzsh and if you want to reload the config file, just run reloadzsh.
NOTE: After every change to the zshrc (ZSH Config) file, always run
source ~/.zshrcto update the shell config.
- Power up your ZSH! Install ZSH Autosuggestions and ZSH Syntax Highlighting to improve productivity. Run the following commands to clone the file in the ZSH custom plugin directory.
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
-
After installing the plugins, source them from your zsh config file and reload the config file. Run
editzshand then addzsh-autosuggestionsandzsh-syntax-highlightingto the plugins list (approx. line 80), using space separators. -
Replacing BASH with ZSH as your default Ubuntu shell. Open CMD/PS then type
ubuntu(orwsl) to load your WLS environment. Runchsh -s $(which zsh)to make ZSH the default shell. Close your terminal and try to runwslorubuntuagain.
NOTE: which is a command which will return the path of a binary or alias. Other commands you can explore in this article
TIP: It's more convenient to use
ubuntuinstead ofwslso you are CD'ed to home at the first prompt.
- Install homebrew for future use.
Run the command below to install homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Run the commands below to set the environment variables for homebrew.
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
Finally, add the line below in your ~/.zshrc file so it picks up the changes above for homebrew.
source ~/.profile
Additional resources:
Cool Themes ¶
- Pygmalion
- Robbyrussel
- Bira
Recommended plugins: ¶
- git
- zsh-autosuggestions
- zsh-syntax-highlighting
- terraform
- autojump
Recommended Aliases:
alias zshcfg="nano ~/.zshrc"
alias tfi="terraform init"
alias tfp="terraform plan"
alias tfa="terraform apply"
alias tfd="terraform destroy"
alias repos="cd /home/YOURUSERNAME/repos"
alias reloadzsh="source ~/.zshrc"
alias home="cd ~/"
alias migration="~/repos/migration"
alias qnet-tf="~/repos/qnet-tf"
alias qnet-tf-modules="~/repos/qnet-tf-modules"
alias azurevnet="~/repos/azurevnet"
alias azuretraining="~/repos/azuretraining"