Skip to content

Instantly share code, notes, and snippets.

@influx6
Forked from roustem/Setting-up-Windows-WSL1.md
Last active March 8, 2020 14:35
Show Gist options
  • Save influx6/78fbd5818ecc882f2175652b615fca3a to your computer and use it in GitHub Desktop.
Save influx6/78fbd5818ecc882f2175652b615fca3a to your computer and use it in GitHub Desktop.
Setting-up-Windows-WSL

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

Disable Smart Quotes

The problem is in the installed keyboard (windows input service).

In your Control Panel > Region and Language > Keyboards and Languages you'll most likely find US Keyboard - International, which is an input service that has the ugly autocomplete feature. Add a new keyboard English - US (or Serbian or any other you like) and make it the default keyboard (in the drop down list above). Remove the "buggy" keyboard. Voila!

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

Move home directory like below

Changing the home directory with WSL is done the same way as in Linux:

Enter bash

  1. Type the command sudo vim /etc/passwd
  2. Find your account's line, which might look like: harry:x:1000:1000:"",,,:/home/harry:/bin/bash
  3. Change the home directory, which above is /home/harry, to the new directory, using WSL notation
  4. Save the file
  5. Exit bash and re-launch it
  6. To test, use the commands:
  7. cd ~
  8. pwd

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

Install nvm and ohmybash

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"

Install linuxbrew to make install apps easier

See Linuxbrew here (https://docs.brew.sh/Homebrew-on-Linux)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

After installation run the ff to add linuxbrew to path

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

Install byobu (you will never regret it, it's sick)

https://www.brianketelsen.com/byobu-wsl/

Install mackup (best tool ever to backup dotfiles)

https://github.com/lra/mackup

Install Mackup with PIP

pip install --upgrade mackup

With linuxbrew

brew install mackup

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 roustem@1password.com  
git config --global user.name Roustem

git config --global url."git@gitlab.1password.io:".insteadOf "https://gitlab.1password.io/"  
git config --global url."git@gitlab.com:".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 roustem@1password.com  
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"

#!/bin/bash
sudo apt update
sudo apt upgrade
sudo apt-get install build-essential curl file git
sudo apt -y purge python-pip
sudo python -m pip uninstall pip
sudo apt -y install python-pip
pip install --upgrade pip
echo "export PATH=\"${HOME}/.local/bin:$PATH\"" >>"${HOME}"/.bashrc
sudo apt remove gnupg gpg
sudo apt install -y gnupg2 fish tree graphviz build-essential unzip socat curl apt-transport-https ca-certificates
sudo apt install -y axel aria2 byobu
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
sudo apt install -y kubectl google-cloud-sd byobu
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
test -d ~/.linuxbrew && eval $(~/.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
brew install hello
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
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
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 -y yarn
# 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 core.filemode false
git config --global core.autocrlf input
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 trinoxf@gmail.com
git config --global user.name Alex Ewetumo
git config --global url."git@gitlab.1password.io:".insteadOf "https://gitlab.1password.io/"
git config --global url."git@gitlab.com:".insteadOf "[https://gitlab.com](https://gitlab.com)"
echo “Test” | gpg --clear-sign
gcloud init
gcloud container clusters get-credentials cluster-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment