Windows Development Environment
Published: 2023-07-12 21:46:34

Are you a Windows user who wants to set up a powerful development environment? Look no further! In this article, I'll guide you through the process of installing and configuring essential tools to create a seamless development experience on Windows. We'll cover setting up WSL2 with Ubuntu, installing Zsh as your default shell, configuring Oh My Zsh, Powerlevel10k, Nerd Font, and more. Let's get started!

**Note:** This guide is based on Windows 11 and Windows 10 version 2004 and higher (Build 19041 and higher); If you are using an older version of Windows 10, the process is the same except for installing WSL, in that case you can find the instructions. [here](https://learn.microsoft.com/en-us/windows/wsl/install-manual)

## Step 1: Install WSL2 and Ubuntu

To kickstart our development environment setup, we'll first install Windows Subsystem for Linux 2 (WSL2) and Ubuntu. Open a PowerShell terminal and execute the following commands:

```powershell
wsl --list --online  # List available Linux distributions
wsl --install -d Ubuntu-22.04  # Install Ubuntu 22.04
```

If you ever need to uninstall a WSL distribution, you can use the following command:

```powershell
wsl --unregister Ubuntu  # Replace 'Ubuntu' with the distribution you want to uninstall
```

## Step 2: Configure WSL

Now that we have Ubuntu installed, we could configure WSL for optimal performance and functionality.

A good source of all the possible configuration options can be found in the official [documentation](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-setting-for-wslconfig).


## Step 3: Install Zsh

Zsh is a powerful shell designed for interactive use and scripting. Let's install it on our Ubuntu distribution by running the following command:

```shell
sudo apt-get install zsh
```

Once Zsh is installed, let's set it as the default shell. Open the `~/.bashrc` file in your favorite text editor:

```shell
vim ~/.bashrc
```

Add the following lines at the end of the file:

```shell
# if running in terminal...
if test -t 1; then
  # ...start zsh
  exec zsh
fi
```

Save the file and execute the following command to apply the changes:

```shell
source ~/.bashrc
```

## Step 4: Install Oh My Zsh

Oh My Zsh is a community-driven framework for managing Zsh configurations. It provides a delightful experience out of the box. Let's install it by running the following command:

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

## Step 5: Install Nerd Font

Nerd Font is a collection of fonts that adds glyphs and icons to various programming-related tools. Download the desired Nerd Font and install it on your operating system. This step may vary depending on your specific font and operating system. I personally use `FiraCode Nerd Font Mono`.

## Step 6: Install Powerlevel10k

Powerlevel10k is a highly customizable Zsh theme that emphasizes speed, flexibility, and an out-of-the-box experience. Additionally, we'll install two extra plugins: `zsh-autosuggestions` and `zsh-syntax-highlighting`. Execute the following commands:

```shell
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
```

## Step 7: Configure Powerlevel10k

Open the `~/.zshrc` file:

```shell
vim ~/.zshrc
```

Add or modify the following lines to configure Powerlevel10k:

```shell
export TERM="xterm-256color"
POWERLEVEL9K_MODE="nerdfont-complete"
ZSH_THEME="powerlevel10k/powerlevel10k"
ENABLE_CORRECTION="true"
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
```

Save the file and execute the following command to apply the changes:

```shell
source ~/.zshrc
```

To run the Powerlevel10k Configuration Wizard at any time, for example to change our previous configuration, execute the following command:

```shell
p10k configure
```

## Step 8: Add Aliases to Zsh

Aliases are shortcuts that make your command-line usage more efficient. Open the `~/.zshrc` file:

```shell
vim ~/.zshrc
```

Scroll to the bottom of the file and add the following custom aliases:

```shell
# ------------------------------------------------------- #
#                   Custom Aliases                        #
# ------------------------------------------------------- #

# Miscellaneous
alias configzsh="vim ~/.zshrc"
alias configvim="vim ~/.vimrc"
alias reloadzsh="source ~/.zshrc"
alias reloadvim="source ~/.vimrc"
alias wttr="curl -s wttr.in/Malmo"
alias python="python3"

# Network
alias mip="hostname -I"
alias ports="lsof -i -n -P"
```

Save the file and execute the following command to apply the changes:

```shell
source ~/.zshrc
```

## Step 9: Set Vim as the Default Git Editor

Let's configure Git to use Vim as the default editor for commit messages. Run the following command:

```shell
git config --global core.editor "vim"
```

## Step 10: Install NVM

NVM (Node Version Manager) is a handy tool for managing multiple versions of Node.js. Install NVM by executing the following command:

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

## Step 11: Create a Working Space

To organize your development projects, create a directory to store all your code and documents. Run the following command to create the directory structure:

```shell
mkdir -p workspace/work/git-repos && cd $_
```

## Step 12: Generate SSH Key for Git Repositories

If you use Git for version control, it's a good practice to generate an SSH key for secure authentication. Run the following command and follow the prompts:

```shell
ssh-keygen -t ed25519 -C "your_email@example.com"
```

After generating the SSH key, you can display it using the following command:

```shell
cat ~/.ssh/id_ed25519.pub
```

## Step 13: Load tmux on Launch Terminal

Tmux is a terminal multiplexer that allows you to manage multiple terminal sessions within a single window. Edit the `~/.zshrc` file:

```shell
vim ~/.zshrc
```

Add the following line at the end of the file to automatically start tmux when launching the terminal:

```shell
if [ "$TMUX" = "" ]; then tmux; fi
```

Save the file and execute the following command to apply the changes:

```shell
source ~/.zshrc
```

By default, Oh My Zsh includes a plugin for tmux. If you haven't done so already, add the plugin to your plugins list and set `ZSH_TMUX_AUTOSTART=true` in your `.zshrc` file. Refer to the Oh My Zsh documentation for more details.

## Step 14: Install Scoop Application

Scoop is a convenient package manager for Windows that allows you to install programs directly from the command line with minimal friction. It offers several advantages:

* **Eliminates permission popup windows**: Scoop installs programs without requiring any pop-up windows for user confirmation.
* **Hides GUI wizard-style installers**: Scoop bypasses the need for manual installation steps or complex graphical interfaces.
* **Prevents PATH pollution**: Unlike traditional installations, Scoop avoids cluttering your system's PATH environment variable with unnecessary entries.
* **Avoids unexpected side-effects**: Scoop manages installations and uninstallations cleanly, ensuring that no unwanted leftovers or conflicts occur.
* **Finds and installs dependencies automatically**: Scoop automatically resolves and installs any dependencies required by the programs you install.
* **Performs all extra setup steps**: Scoop takes care of any additional configuration steps needed to ensure the installed program functions correctly.

Furthermore, Scoop downloads and manages packages in a portable way, neatly isolating them within the `~\scoop` directory. It doesn't install files outside its designated home, providing a clean and organized installation process. Additionally, you can place a Scoop installation anywhere you prefer on your system.

To install Scoop, execute the following command:

```powershell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser # Optional: Needed to run a remote script the first time
irm get.scoop.sh | iex
```

With Scoop installed, you now have a powerful package manager at your fingertips, making it easy to install and manage your favorite programs from the command line.

I created a script to install some commonly packages that are typically included in a new development machine setup. These packages cover a range of categories, including version control, utilities, graphics, collaboration, editors, browsers, development tools, office suites, gaming, music, and fonts.

```powershell
# Git
scoop install main/git

# Add the extra buckets
scoop bucket add extras
scoop bucket add versions
scoop bucket add java
scoop bucket add nerd-fonts

# Update Scoop Buckets
scoop update

# Java
scoop install java/oraclejre8

# Utils
scoop install main/7zip extras/totalcommander extras/powertoys extras/obs-studio extras/vlc extras/rufus

# Graphics
scoop install extras/xnviewmp extras/paint.net

# Colaboration
scoop install extras/slack extras/discord

# Editors
scoop install extras/notepadplusplus

# Browsers
scoop install versions/firefox-developer extras/brave

# Dev Tools
scoop install versions/vscode-insiders extras/windows-terminal extras/postman extras/robo3t extras/dbeaver

# Office
scoop install extras/wpsoffice extras/foxit-reader

# Gaming
scoop install versions/steam

# Music
scoop install extras/aimp

# Fonts
scoop install nerd-fonts/FiraCode-NF-Mono
```

These are just a selection of packages, and you can customize this list based on your specific requirements and preferences. Here's a breakdown of the packages I install:

**Git**: Version control system for tracking changes in source code.

**7-Zip**: File compression and decompression utility.

**Total Commander**: File manager with a dual-pane interface and various advanced features.

**PowerToys**: Set of utilities that enhance Windows functionality and productivity.

**OBS Studio**: Open-source software for video recording and live streaming.

**VLC**: Multimedia player that supports a wide range of audio and video formats.

**Rufus**: Utility for creating bootable USB drives.

**XnView**: Image viewer and organizer with support for various file formats.

**Paint.NET**: Image and photo editing software with a user-friendly interface.

**Slack**: Team communication and collaboration platform.

**Discord**: Voice, video, and text communication platform for gamers and communities.

**Notepad++**: Feature-rich text editor with support for multiple programming languages.

**Firefox Developer Edition**: Web browser with developer tools and advanced features.

**Brave**: Privacy-focused web browser that blocks ads and trackers by default.

**Visual Studio Code (Insiders)**: Lightweight and highly extensible code editor.

**Windows Terminal**: Modern and customizable terminal application for Windows.

**Postman**: Collaboration platform for API development and testing.

**Robo 3T**: MongoDB database management tool.

**DBeaver**: Universal database tool for managing and exploring database systems.

**WPS Office**: Office suite with word processing, spreadsheet, and presentation capabilities.

**Foxit Reader**: PDF reader with features for viewing, editing, and annotating PDF documents.

**Steam**: Digital distribution platform for video games (It's very important to have time to relax).

**AIMP**: Audio player with support for various audio formats and customizable interface.

**Fira Code (Nerd Font)**: Monospaced font with programming ligatures.

Feel free to modify this list according to your preferences or specific needs.

You can find the [script ](https://github.com/aagamezl/dev-env-config/blob/master/scoop/install.ps1)and other useful configuration files in my configurations [repository](https://github.com/aagamezl/dev-env-config).

To execute the script open a PowerShell terminal and execute the following command:

```powershell
irm https://gist.githubusercontent.com/aagamezl/f677266d6cfdcbe41b0e4c5ce7ea68d4/raw | iex
```

## Step 15: Install Docker on WSL2

Docker is a popular containerization platform that allows you to build, distribute, and run applications using lightweight, isolated containers. In this section, we'll guide you through the process of setting up Docker on WSL2 (Windows Subsystem for Linux 2) for a seamless container development experience. We'll cover starting the Docker service, installing Docker Engine, Docker Compose, and Lazydocker. Let's get started!

This command starts the Docker service, allowing you to use Docker commands and interact with containers.

### Install Docker

To install Docker Engine on Ubuntu, we'll follow the official Docker documentation. You can find detailed installation instructions [here](https://docs.docker.com/engine/install/ubuntu/). Open a terminal in your WSL2 Ubuntu distribution and execute the following command:

```bash
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

This command installs Docker Engine along with additional plugins required for Docker Buildx and Docker Compose.

### Start Docker Service

Before we proceed with the installation, let's ensure that the Docker service is up and running. Open a terminal in your WSL2 Ubuntu distribution and execute the following command:

```bash
sudo service docker start
```

### Install Docker Compose

Docker Compose is a tool that simplifies the process of defining and running multi-container Docker applications. To install Docker Compose, execute the following commands:

```bash
sudo curl -SL https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
```

This command downloads the Docker Compose binary and saves it to the `/usr/local/bin` directory.

```bash
sudo chmod +x /usr/local/bin/docker-compose
```

This command makes the Docker Compose binary executable.

### Install Lazydocker

Lazydocker is a terminal-based UI tool that provides a simplified interface for managing Docker containers and services. To install Lazydocker, execute the following command:

```bash
curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash
```

This command downloads and installs Lazydocker on your system.

### Start the Lazy Docker Manager

Once Lazydocker is installed, you can start it by executing the following command:

```bash
lazydocker
```

This command launches the Lazydocker interface, allowing you to manage your Docker containers and services with ease.

By following these steps, you've successfully set up Docker on your WSL2 Ubuntu distribution. Docker provides a powerful platform for developing and running containerized applications, enabling you to build and deploy software in a consistent and efficient manner.

## Conclusion

Congratulations! You've successfully set up your Windows development environment with a powerful set of tools and configurations. Enjoy coding and have fun exploring the possibilities of your new setup!

In this article, we've walked through the process of setting up a Windows development environment that will enhance your productivity and make your coding experience more enjoyable. We covered installing WSL2 with Ubuntu, configuring Zsh as the default shell, setting up Oh My Zsh, Powerlevel10k, and Nerd Font, along with additional tools like NVM and Scoop, Docker and Docker Compose. By following these steps, you've created a robust and customizable development environment on your Windows machine. Happy coding!

If you have any questions or need further assistance, please let me know in the comments section below or message me at [Twitter](https://twitter.com/aagamezl) or [LinkedIn](https://www.linkedin.com/in/alvarojoseagamezlicha).