Skip to content

Instantly share code, notes, and snippets.

@symmetryninja
Last active April 8, 2020 10:58
Show Gist options
  • Save symmetryninja/6ca99d4e94cd1724e6acfac59850bae4 to your computer and use it in GitHub Desktop.
Save symmetryninja/6ca99d4e94cd1724e6acfac59850bae4 to your computer and use it in GitHub Desktop.

Setting up WSL v1 to linux on windows

THIS IS A WIP

Install WSL and fix pathing

Install Ubuntu from the microsoft app store.

There's some weird things with pathing, by default, all drives including C are mounted in /mnt but for docker (and other things) to play nice we need to change c to be mounted in / - edit the /etc/wsl.conf (sudo)

sudo vim /etc/wsl.conf

This file should look like this.

[automount]
root = /
options = "metadata"

Apps etc

This installs all the build requirements i have - including docker and pyenv, you may not need all of this

sudo apt update
sudo apt upgrade
sudo apt-get install -y docker make wget curl build-essential libssl-dev \
zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl gnupg2 pass

Docker

You need to run docker on windows and "proxy" docker calls from WSL to windows daemon.

Windows

Install docker for windows

In docker for windows config, tick "expose daemon on tcp://localhost:2375 without TLS".

In WSL

Install docker (above)

Now you need to point the WSL docker to the one running on windows:

echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc

Cleanup and confirm

At this point, we should be completely configured but because you're running windows and containers and micro-instances and all sorts of confusion, you should reboot your machine.

Once rebooted, run this in WSL

docker version

In my WSL instance I get:

Client:
 Version:           18.09.5
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        e8ff056
 Built:             Thu May  9 23:11:19 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea
  Built:            Wed Nov 13 07:29:19 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

If this command runs at all, docker is working.

You should also be able to see the root of your C drive by doing this:

ls /c/

If not, your /etc/wsl.conf may not be configured correctly.

Git and Bash/sh etc

Getting git to play nice for both sides is a bit of a trick WSL and windows don't support all the same file attributes... which sucks... especially with folders, also for some reason by default all line endings on windows should be crlf apparently...

If you aren't doing much windows development, run this in all terminals to prevent git from changing the line endings:

  • WSL terminal
  • Gitbash terminal
  • Windows command prompt
  • powershell
  • powershell.* (for good measure)

To better navigate the mixed mac/linux/windows dev environments, make sure your IDE's do not use crlf and use only lf - code pushes the line endings sometimes.

git config --global core.autocrlf false
git config --global core.eol lf
# also if you don't want that pesky execute attribute goin awry
git config --global core.fileMode false

Python

By default, wsl/ubuntu has python2.7.x as it's default python instance. removing the default python instance is not a good idea and changing the defaults to python 3 is also a bad idea....

To get around this, I want to use pyenv sourced from here

Dependant packages

were all installed up the page!

install pyenv

curl https://pyenv.run | bash

get some env based stuff

put this in your ~/.profile

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Install python 3.7 and set it to default

pyenv install 3.7.4
pyenv global 3.7.4

Useful tools

Before we get too far, install AWS cli. If you already have awscli installed as an operatign system package - aka via apt - use the OS package.

sudo apt install awscli

if you don't, use the pip installation (it's usually more current).

pip install awscli

Stackup is useful for deploying stacks JQ is useful for json respones

sudo gem install stackup
sudo apt install jq

Sources

Other useful links

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