Skip to content

Instantly share code, notes, and snippets.

@ecarlson94
Last active April 17, 2024 14:54
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ecarlson94/283102ffd2f2473d41e7c9965be8fdd4 to your computer and use it in GitHub Desktop.
Save ecarlson94/283102ffd2f2473d41e7c9965be8fdd4 to your computer and use it in GitHub Desktop.
WSL Configuration

Installing WSL (windows subsystem for linux)

Running the azure-team terraform make file to create your infrastructure may not work on a Windows machine. If you cannot get it to run, install a linux distribution where you will exectute the tf files. Setting up a distribution with all of the right dependencies does involve a bit of setup to get it configured properly. The following is a list of steps you'll need to complete:

Install WSL

Links

Steps

  1. Enable WSL for windows by running the following commands in an elevated powershell session:

    • Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
    • Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
  2. Restart your machine.

  3. Install the linux distribution of choice (Ubuntu 18.04 LTS is what these steps were developed with).

    • If the windows store is enabled, install your distribution from there.
    • Otherwise you can do a manual installation by following these instructions.
  4. After installation, open Ubuntu (or the distribution you installed) and let it initialize itself.

    • You'll need to set a username and password.
    • When you use the sudo command you'll be prompted for this password.
  5. Once initialized do an update and upgrade.

    • sudo apt update && sudo apt upgrade
  6. Enable and default WSL2 by running the following commands in an elevated powershell session (Currently only on Windows Insiders Slow Track)

    • wsl --set-version <distro> 2
    • wsl --list --verbose to verify
    • wsl --set-default-version 2

Change the mount point from /mnt/c to /c

This step is optional but it makes it more convenient when running the terraform files if your linux and windows file structures match.

Links

Steps

  1. Start Ubuntu (or your other installed distribution)
  2. Run this command to open the nano text editor:
    • sudo nano /etc/wsl.conf
  3. Paste this snippet at the bottom of the file:
    # Enable extra metadata options by default
    [automount]
    enabled = true
    root = /
    options = "metadata,umask=22,fmask=11"
    mountFsTab = false
    
    # Enable DNS – even though these are turned on by default, we’ll specify here just to be explicit.
    [network]
    generateHosts = true
    generateResolvConf = true
    
  4. Press Ctrl + O to save the changes, then Ctrl + X to exit the editor
  5. Restart the WSL service by running Restart-Service -Name "LxssManager" in an elevated powershell session

Install homebrew

This step is optional but it makes it significantly easier to install all of the required dependencies. If you'd rather install those manually, skip this step

Links

Steps

  1. In Ubuntu (or your other distribution), run the following command:
    • sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
  2. Add homebrew to your 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 "test -f $(brew --prefix)/bin/brew && eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
    echo "test -f $(brew --prefix)/bin/brew && eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
    
  3. Then run:
    • sudo apt-get install build-essential curl file git

Set up git credential manager (Optional)

This is optional but it keeps you from having to enter git username/password each time.

In Ubuntu run this command:

  • git config --global credential.helper "/c/Program\ Files/Git/mingw64/bin/git-credential-manager-core.exe"

Install sqlcmd (Optional)

Links

Steps

In Ubuntu (or your installed distribution) run the following commands:

  1. curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  2. curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
  3. sudo apt-get update
  4. sudo apt-get install mssql-tools unixodbc-dev
  5. sudo apt-get update
  6. sudo apt-get install mssql-tools
  7. echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
  8. echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
  9. source ~/.bashrc
@mromanch
Copy link

The location for the GCM moved in Git for Windows v2.36.0. It is now located at /mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager-core.exe. (If you are changing the mount point, it would be /c/Program\ Files/Git/mingw64/bin/git-credential-manager-core.exe.)

release notes: https://github.com/git-for-windows/build-extra/blob/main/ReleaseNotes.md#new-features-1
pull request: git-for-windows/build-extra#406

@ecarlson94
Copy link
Author

Thank you, @mromanch. I have made the update. However, I should note that the process for installing WSL has changed quite a bit since the release of WSL2. I would not suggest anyone use this gist anymore. Those looking to install WSL should look here instead: https://docs.microsoft.com/en-us/windows/wsl/install#install-wsl-command

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