Make sure to read the main Readme documentation and ensure you have pre-requisites installed.
Do read official documentation from Microsoft for latest updates
Update wsl to ensure there is latest WSL kernel isntalled.
wsl --update
If you have not installed Debian already then install using command
wsl --install Debian --version 2
It will ask for user name to be setup. Provide the required information and you will be logged in the system with your account.
Intial install size of the Debian VHDX is about 200-300MB.
Do check that you have latest version of Debian
cat /etc/os-release
At the time of writing "bullseye" or version 11 is the latest version of Debian OS.
If for whatever reason you have old version of Debian (I got by default Debian 9), then make sure to update it to the latest release. There are upgrade documentation made avilable by Debian for each version. make sure to follow the guides.
NOTE:
- Make sure to follow the 2 step upgrade guide. It usually make this run smooth.
- Debian has step by step upgrade from version to version. e.g. direct upgrade from 9 to 11 is not supported.
Make sure you update to latest release of packages
sudo apt update && sudo apt upgrade -y
- wget
- curl
- unzip
- lsb-release
I have about 150 GB on my C: drive. But for my experience, this is not an enough space especially if you want to have multiple WSL with additional softwares installed e.g. docker, kubernetes and other images.
At the time of this writing, this is no direct command to move a distribution to another location. This is acheived by export/import commands for WSL.
By default WSL distribution is installed on %userprofile%\AppData\Local\Packages\TheDebianProject.DebianGNULinux....\LocalState\ext4.vhdx"
To move it to another location follow below steps. My choice below is D drive. Replace it with any other drive that you have.
-
Create a directory for your wsl distros virtual drives on the drive
cd d: mkdir wsl/debian11
-
Create a directory to store your wsl exports/backups
mkdir wsl_backups
-
Shutdown WSL
wsl --shutdown wsl -l -v
-
Export old Debian. This will export the WSL2 distribution named Debian to the provided location.
wsl --export Debian ./wsl_backups/debian.tar
-
Import new Debian at new location. This will import the exported .tar file as a new Debian distribution named debian11 with .vhdx file stored at the given location.
import debian11 ./wsl/debian11 ./wsl_backups/debian.tar
-
Login to the new distribution. Information is same as your original system; in this case Debian
wsl -d debian11 -u "username"
-
Remove old distribution to clear up the space on C drive
wsl --unregister Debian
NOTE: In case you want to keep the name of the distribution as original e.g. Debian then you need to execute step 7 before step 5.
-
Create new entry for the system (debian11) in Windows Terminal. This is quite easy. Simply exit Windows Terminal and start it again. You should have default entry created for it.
-
Set default user for the new distro. This is to avoid logging in as root user. Add/update [user] section in /etc/wsl.conf
[user] default = defaultusername
For detailed configuration parameters for WSL (global and per distribution) please check Microsoft's official documentation.
By default WSL distros open with root user and in the directory from which you execute wsl or default user directory. There are different ways, but I prefered to configure Windows Terminal entry to configure the entry. Open Windows Terminal Settings and on the left side select your distribution. Set below options in Tab General > commandline
wsl.exe ~ -d debian11 -u username
It opens the new session in home directory in Linux Distro given by "~" and with user "username". Do replace "username" with the user that you want to configure.
This setup gives the flexibility to configure mutiple Windwows Terminal sessions with different users and starting directories if one wants.
-
Install ZSH and set it as your default shell
sudo apt install zsh -y chsh -s $(which zsh)
-
Logout, close WSL session and login in again
Microsoft has official documentation on Git setup on WSL. Please read that for up-to-date information and further details.
Git needs to be installed on each WSL distro, if we want to use WSL distro's filesystem as the project repositories.
sudo apt install git -y
There are different ways to setup GCM in WSL environment.
- With Git for Windows
- Without Git for Windows
Recommedation as per the GCM documentation is to use with Git for Windows. However, in my case I had no plan to have development environment in Windows. For this reason only GCM is installed in Windows and 2nd option is chosen. Below steps are for the 2nd option.
-
Install GCM on Windows from the source
-
Configure git config in WSL
git config --global credential.helper "/mnt/c/Program\ Files\ \(x86\)/Git\ Credential\ Manager/git-credential-manager-core.exe" # For Azure DevOps support only git config --global credential.https://dev.azure.com.useHttpPath true
-
In windows set envoronment variable WSLENV. From and Administrator cmd prompt execute
SETX WSLENV %WSLENV%:GIT_EXEC_PATH/wp
-
Restart WSL and Windows
To know more, read official documentation from GitHub. Linux specific installation instructions are available at github.
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
Provide support for large file support for github repos.
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
git lfs install
Now one can configure large files to be handles by github LFS. You can manually add files int the repo with git lfs track *.psd
or you can edit .gitattributes
file
Rather than me saying anything about it, just read on Oh My ZSH website. Atleast for me, with its configurable plugins and themes, it made working on Linux shell easy and intersting. I am not one of those geeks who like to remember every command and like black an white screen!
-
Install pre-requisities. if you have followed all the steps above then pre-requistes are already installed.
-
Install Oh My ZSH
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
-
- install recommended font - Meslo Nerd font
- Install powerlevel10k theme
# Clone the repository git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
-
Configure plugins for Oh My ZSH. Add below plugins to
~./zshrc
to enable autocompletionsplugins=(git gh)
-
Install zsh auto-suggestions. Based on the installation type procedure may change. For Oh My ZSH method is below.
-
Copy the plugin
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
-
Add plugin in the
.zshrc
fileplugins=( # other plugins... zsh-autosuggestions )
-
Based on your terminal color layout, you might have configure parameter
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE
. For Oh My ZSH, you can edit that parameter in$ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
.
-
This is another way to beautify your terminal. Oh My Posh seems to cover only themes, while oh My ZSH covers themes and plugins. Both can work together as well. You can make your choice based on your preferences.
This section is based on these nicely documentated articles by Stefan. Here I am just highlighting main points and issues I faced.
-
Install ZSH and set it as your default shell, if not already done.
-
Install Oh My Posh created by Jan De Dobbeleer
sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh sudo chmod +x /usr/local/bin/oh-my-posh
-
Download themes
mkdir ~/.poshthemes wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip unzip ~/.poshthemes/themes.zip -d ~/.poshthemes chmod u+rw ~/.poshthemes/*.json rm ~/.poshthemes/themes.zip
-
Install Nerd Fonts. This is done on Windows. I just installed Meslo LGM Nerd Font.
- This was the tricky part to get right.
- It turns out that are some compaitbility issues between different OSes.
- The github repository for Nerd Fonts provides all the various options and choices to install fonts.
- After some trials I relized I had to install what is called "Windows compatible" Nerd Fonts.
- Another challenge is to match the font name when it is installed with names given in the downloaded file names.
-
Set Meslo LGM Nerd Font in the Windows Terminal settings > Appearance > Font face. I set it up as default from my Windows Terminal. You can ofcourse select different font for different distro.
-
Activate Oh My Posh on ZSH. For this one need to add Oh My Posh inialization scripts with selected theme in
.zshrc
file# Oh My Posh Theme Config eval "$(oh-my-posh --init --shell zsh --config ~/.poshthemes/powerlevel10k_rainbow.omp.json)"
If you have Oh-my-ZSH also installed then comment out the below line in
~/.zshrc
# ZSH_THEME="powerlevel10k/powerlevel10k"
-
Customize Oh My Posh themes to your liking. There are variety of themes available for Oh My Posh. You can also combine options from different themes by changing theme's json file. You can read about configuration possibilities on the website.
NOTE: visualizations are valid for both Oh My ZSH and Oh my Posh, based on your configuration.
You might have read the documentation earlier to know what it is about. Here I am capturing some results for the sake of completeness on my setup.
-
Install Visual Studio Code in Windows.
-
Install Remote Development Extension pack. If you are not going to use docker or other remote SSH server then you can only install Remote WSL extension.
-
Open your project folder in WSL distro in VS Code. On your WSL shell in the appropriate folder execute
code .
-
Alternatively one can also use Remote WSL extension commands from VS code command palette open a certain folder for development.
-
When VS Code is started for the first time in WSL distro it will installe VS Code server in WSL distro to allow connections from VS Code client from Windows.
-
Install extensions inside VS code remote. This is needed based on the extension. e.g. if you use python then Python extension needs to be installed on each WSL distibution. Some extensions are only required to be installed on Windows. VS Code prompts and give option to WSL install for applicable extensions.
NOTE: When you open terminal window in Remote WSL session. VS Code opens terminal with default user configured for that WSL distro, which is usually root user. You can either switch to your desired user in terminal for commands or set the default user to the required one before opening VS Code Remote WSL session. Currently there is no option to select/configure a user per session/workspace./project.
Export the WSL Debian image. Other images can then be build on top of this image.
wsl --export debian11 ./wsl_backups/deb11base.tar | tar -czf ./wsl_backups/deb11base.tar.gz ./wsl_backups/deb11base.tar
Note: Exported image size is now about 300MB.