Skip to content

Instantly share code, notes, and snippets.

@lipex360x
Last active February 9, 2024 19:52
Show Gist options
  • Save lipex360x/5f8fb16902377a731d501a01568e36e0 to your computer and use it in GitHub Desktop.
Save lipex360x/5f8fb16902377a731d501a01568e36e0 to your computer and use it in GitHub Desktop.
WSL Environmnt

Windows PowerShell Admin (PWS)

Right Button in Menu



Hyper-V - Windows Pro Only

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All



Enable LongPaths

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force


Chocolatey Install

Set-ExecutionPolicy AllSigned

Get-ExecutionPolicy

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

choco --version

  • Choco Store

https://chocolatey.org/packages



Apps Install

  • FiraCode: choco install firacode -y

  • Windows Terminal: choco install microsoft-windows-terminal -y

  • Gsudo (Exec Apps as Admin in W. Terminal): choco install gsudo -y

  • VSCode Configs: choco install vscode -y

  • BeeKeeper: choco install beekeeper-studio.install -y

  • DBeaver: choco install dbeaver -y



WSL Environment

  • Configurations

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart Windows

wsl --set-default-version 2



WSL Install

  • Ubuntu Download

18.04 LTS

20.04 LTS

All Versions (amd64-wsl.rootfs.tar.gz)

  • Distro Import

wsl --import <DISTRO_NAME> <FOLDER_DESTINATION [exp: c:\wsl]> .<FILE_PATH>\ubuntu.gz

  • Example
wsl --import ubuntu . ubuntu.gz

  • Terminal Download (alternative)

cd c:\ ; mkdir wsl ; cd wsl ;

Invoke-WebRequest -Uri https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-wsl.rootfs.tar.gz -OutFile ubuntu.tar.gz -UseBasicParsing


  • Uninstall WSL Distro:

wsl --terminate distroName

wsl --unregister distroName



WSL Limit Resources (Optional)

  • Create .wslconfig

function touch {set-content -Path ($args[0]) -Value ($null)}; cd $home; touch .wslconfig ; code .wslconfig

[wsl2]
memory=3GB   # Limits VM memory in WSL 2 up to 3GB
processors=4 # Makes the WSL 2 VM use two virtual processors
swap=2GB # Swap Memory

More Configurations



Windows Terminal

"profiles": 
{
  "defaults": {
    "colorScheme": "Dracula",
    "face": "Fira Code",
    "size": 10
  },

...
  • WSL Launch
{
    "name": "distroName",
    "icon": "c:/wsl/ubuntu.ico",
    "startingDirectory": "//wsl$/ubuntu/home/<user_name>/",
    "commandline": "wsl.exe -d distroName"
}
  • PowerShell Admin Startup
{
"commandline": "powershell.exe gsudo",
...
}
  • Git Bash
{
  "commandline": "%PROGRAMFILES%/git/usr/bin/bash.exe -i -l",
  "guid": "{00000000-0000-0000-ba54-000000000002}",
  "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
  "name": "GIT Bash",
  "startingDirectory": "%USERPROFILE%"
},
{
    "background": "#1E1F29",
    "black": "#000000",
    "blue": "#BD93F9",
    "brightBlack": "#555555",
    "brightBlue": "#BD93F9",
    "brightCyan": "#8BE9FD",
    "brightGreen": "#50FA7B",
    "brightPurple": "#FF79C6",
    "brightRed": "#FF5555",
    "brightWhite": "#FFFFFF",
    "brightYellow": "#F1FA8C",
    "cursorColor": "#BBBBBB",
    "cyan": "#8BE9FD",
    "foreground": "#F8F8F2",
    "green": "#50FA7B",
    "name": "Dracula",
    "purple": "#FF79C6",
    "red": "#FF5555",
    "selectionBackground": "#44475A",
    "white": "#BBBBBB",
    "yellow": "#F1FA8C"
}

๐Ÿ‘† Go to Content Index

Windows Subsystem Linux Linux Register User

  • Set User Name

export NEWUSER=<user_name>

  • Create User
adduser $NEWUSER
usermod -aG sudo $NEWUSER
  • Grant Sudo Access with No Password

echo "$NEWUSER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$NEWUSER

  • Set Default Terminal User

echo -e "[user]\ndefault=$NEWUSER" > /etc/wsl.conf

  • Terminate WSL Distro: wsl --terminate <distro_name>

  • List All Users

cut -d : -f 1 /etc/passwd

  • Go to root user in Terminal
sudo su -
whoami

Windows Subsystem Linux WSL Startup

  • Start WWW Folder

sudo apt update && sudo apt upgrade -y && sudo apt install build-essential net-tools zip -y && cd && mkdir www

  • Optional

cd /mnt/c/ && mkdir www && cd


Windows Subsystem Linux Terminal ZSH

  • Install ZSH

sudo apt install zsh -y

  • Oh-My-ZSH Install

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

  • ZINIT Install

sh -c "$(curl -fsSL https://git.io/zinit-install)"

sudo git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt"

sudo ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"



Windows Subsystem Linux SSH Generate

ssh-keygen -t rsa -b 4096 -C "mail@mail"

cd ~/.ssh && more id_rsa.pub && cd

chmod 400 ~/.ssh/id_rsa

  • GitHub test Connect

ssh -T git@github.com



Windows Subsystem Linux ASDF - Tool Version Manager

  • ASDF Install

git clone https://github.com/asdf-vm/asdf.git ~/.asdf

  • Command List: Here
  • Node LTS Version: Here

  • Install Node Plugin : asdf plugin add nodejs
  • List Node Versions: asdf list-all nodejs
  • Install Node LTS Version: asdf install nodejs lts
  • Set Global Node LTS Version: asdf global nodejs lts
  • Set Local Node Version: asdf local nodejs XX.XX.X


Windows Subsystem Linux pnpm

npm install -g pnpm



Windows Subsystem Linux Docker Environment

sudo apt remove docker docker-engine docker.io containerd runc

sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io -y && sudo usermod -aG docker $USER

  • Start Docker

sudo service docker start

  • Docker Login

sudo docker login --username USERNAME

  • Docker Hello World

sudo docker run hello-world

  • Clear Docker

sudo docker system prune -a

  • Docker User Permission (alternative)

sudo chmod 666 /var/run/docker.sock

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R

sudo chmod g+rwx "/home/$USER/.docker" -R


  • Docker Compose Install

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

sudo docker-compose -v



Windows Subsystem Linux NVM install

Execute curl command in Terminal

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

  • Restart Windows Terminal

  • Update Version

(
  cd "$NVM_DIR"
  git fetch --tags origin
  git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"


Windows Subsystem Linux Yarn install

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 update && sudo apt install yarn -y && sudo apt remove nodejs -y && yarn --version



Windows Subsystem Linux zshrc File template

code ~/.zshrc



Windows Subsystem Linux Heroku Install

curl https://cli-assets.heroku.com/install.sh | sh

heroku login



๐Ÿ‘† Go to Content Index

Export WSL Distro

  1. Shutdown all WSL distros
wsl --shutdown
  1. Export distro to .gz file
wsl --export <distro_name> <path>\<filename>.gz
  1. Remove Distro (optional)
wsl --unregister <distro_name>
  1. Import from .gz file
wsl --import <distro_name> <FolderName [exp: c:\wsl]> .\filename.gz
  1. Install Online
wsl -l --online

wsl --install -d distro-name

WSL Pre Configured (optional)

WSL Clean 20.04 with Docker and Yarn


๐Ÿ‘† Go to Content Index

Windows Docker Install

choco install docker-desktop -y

  • Restart Windows

  • Settings

General : [ ] Start Docker Desktop when you log in

General : [x] Use the WSL 2 based engine

Resources > WSL Integration : [x] Enable integration with my default WSL distro


๐Ÿ‘† Go to Content Index

Windows Apps

choco install firacode -y;
choco install microsoft-windows-terminal -y;
choco install vscode -y;

choco install dbeaver -y;
choco install beekeeper-studio -y;
choco install mongodb-compass-isolated -y;

choco install insomnia-rest-api-client -y;

choco install docker-desktop -y;
choco install docker-compose -y;

choco install lightshot -y;
choco install vlc -y;
choco install winrar -y;
choco install spotify -y;

choco install gsudo -y;
choco install git -y;
choco install office365proplus --params '/Language: pt-BR';
choco install qbittorrent -y;
choco install teamviewer -y;
choco install vnc-viewer -y;
choco install discord -y;
choco install anki -y;

๐Ÿ‘† Go to Content Index

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