Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ramaID/2be852b08ffbae017dfa2f1c3f0c9172 to your computer and use it in GitHub Desktop.
Save ramaID/2be852b08ffbae017dfa2f1c3f0c9172 to your computer and use it in GitHub Desktop.
Setting-up-Windows-WSL1

Setting up Windows 10 and WSL

This document describes how to set up Windows 10 for cross-platform development (Go, NodeJS, etc) with Windows Subsystem for Linux (WSL).

Resources

Most of the information here is collected from

WSL Setup

  1. Download Brave beta and Firefox browsers, make either default.
  2. Install 1Password for Windows, sign into personal and company accounts.
  3. Add 1Password X extension in Brave and Firefox
  4. Enable WSL and install latest version of Ubuntu from Microsoft Store
  5. Create C:\home directory, move user's home folder there and update /etc/passwd with the new location
# in /etc/wsl.conf
# Enable extra metadata options by default
[automount]
enabled = true
options = "metadata,umask=22,fmask=11"
mountFsTab = true

Default User

Ubuntu will create a default user on the initial run. It can also be done manually:

  1. Create new user in Ubuntu: useradd -Um roustem
  2. Make sure that user is added to sudoers
  3. Change default user (using PowerShell Admin):
ubuntu config --default-user roustem  
sc stop LxssManager
sc start LxssManager

Install Ubuntu Apps

sudo apt update
sudo apt upgrade
sudo apt remove gnupg gpg
sudo apt install gnupg2 fish tree graphviz build-essential unzip

Go

export GO_VERSION=1.11.4
curl -O "https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz"
sudo mv /usr/local/go /usr/local/go.bak.$GO_VERSION # if installing new version
sudo tar -C /usr/local -xzf go$GO_VERSION.linux-amd64.tar.gz

NodeJS

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt	-get install -y nodejs

Yarn

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install yarn

GPG and Git

# Export key to `key.asc` file and then import
gpg --import key.asc
# or add --pinentry-mode if there is ap problem with entering the password
gpg --import --pinentry-mode loopback key.asc

git config --global commit.gpgsign true  
git config --global user.signingkey E25C1E01F3A98447  
git config --global gpg.program /usr/bin/gpg  
git config --global user.email [email protected]  
git config --global user.name Roustem

git config --global url."[email protected]:".insteadOf "https://gitlab.1password.io/"  
git config --global url."[email protected]:".insteadOf "[https://gitlab.com](https://gitlab.com)"

Debugging gpg signing:

echo “Test” | gpg --clear-sign

Google Cloud SDK

https://cloud.google.com/sdk/docs/downloads-apt-get

sudo apt install kubectl
gcloud init
gcloud container clusters get-credentials cluster-dev

Install Windows Apps

  1. Visual Studio Code
  2. Git
  3. Go
  4. WSLtty
  5. Gpg4win
  6. Ditto

Configure git

After installing Go, press Win-S, type PATH and change the GOPATH to C:\home\roustem\go. This will make sure that GOPATH is shared with WSL and Go can pickup all libraries and vendored code.

git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

git config --global commit.gpgsign true  
git config --global user.signingkey E25C1E01F3A98447  
git config --global user.email [email protected]  
git config --global user.name Roustem

Solving Git interoperability with WSL

git config --global core.filemode false
git config --global core.autocrlf input

Also, make sure that local .git/config file has correct settings as well.

Note: you might have to do this without --global in the repo as well.

MinGW (optional)

Install MinGW to get access to make and other command line tools. Update PATH to Include

C:\MinGW\bin
C:\MinGW\msys\1.0\bin

Improving WSL Performance

Based on Speeding up WSL I/O ..., turn off Windows Defender protection for some folders and processes:

Exclude folder: %USERPROFILE%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc Exclude processes:

  • git
  • node
  • npm
  • dpkg
  • go

Securing Docker

WSL Interoperability with Docker

go get -d github.com/jstarks/npiperelay
// on Windows:
go install  github.com/jstarks/npiperelay
// in WSL:
sudo apt install socat
sudo apt install docker.io

touch ~/docker-relay
chmod +x ~/docker-relay
vim ~/docker-relay

// contents of ~/docker-relay
#!/bin/sh
exec socat UNIX-LISTEN:/var/run/docker.sock,fork,group=docker,umask=007 EXEC:"npiperelay.exe -ep -s //./pipe/docker_engine",nofork

// end ^^^

sudo adduser roustem docker

Configure Ditto

Set keyboard shortcut to Alt-V Exclude 1Password binary Add image clipboard type

Miscellaneous Windows Tips

Keyboard Shortcuts:

  • Cmd-Shift-S – take a screenshot and save it to clipboard

  • Win-. – show emoji panel (see Advanced Keyboard settings to control if emoji panel closes automatically) Configure system and user path:

  • Win-S, type "PATH" Configure taskbar:

  • Cmd-S, type "system icons"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment