• U6_810570
  • 382.1KB
  • zip
  • 0
  • VIP专享
  • 0
  • 2022-06-15 07:49
  • unix-under-windows-master
  • screenshot.png
  • README.md
<img src="https://assets.ubuntu.com/v1/29985a98-ubuntu-logo32.png" width="120" align="right" alt=""/> <img src="https://upload.wikimedia.org/wikipedia/commons/5/5f/Windows_logo_-_2012.svg" width="120" align="right" alt=""/> Author: [Dr. Ralf S. Engelschall](mailto:rse@engelschall.com)<br/> Version: 2.2.1 (2020-10-14) # Unix Environment under Windows This is a documentation on how to setup a reasonable but opinionated Unix development environment under [*Microsoft Windows 10*](https://windows.com) (Pro edition, 64-bit mode, version &ge; 1809) with the help of the native [*Windows Subsystem for Linux (WSL)*](https://devblogs.microsoft.com/commandline/), the [*Ubuntu*](https://www.ubuntu.com/) GNU/Linux distribution, Dr. Ralf S. Engelschall's [*Unix dotfiles*](https://github.com/rse/dotfiles) shell environment, the terminal emulator [*MinTTY/WSLTTY*](https://github.com/mintty/wsltty) and the [*Docker Desktop for Windows*](https://www.docker.com/products/docker-desktop) container execution platform. ![screenshot](screenshot.png) > Notice: In short, the crux of this setup in contrast to the usual standard WSL setups is: > > - convenient root access (password-less `sudo`) > - reasonably mapped home directory (`/c/Users/$USER`) > - essential Unix shell configurations for Bash, Vim, Vifm, TMux and Git ("dot-files") > - essential Unix shell tools (OpenSSH, RSYNC, etc) > - additional WSL shell tools (`wsl-open`) > - improved host terminal emulator (MinTTY/WSLTTY) > - host SSH agent with transparent access from within WSL (`weasel-pageant`) > - host Docker engine with transparent access from within WSL (`$DOCKER_HOST`) > - optionally, essential programming languages (C/C++/Go/Perl/JavaScript/Java) ## Install Windows Subsystem for Linux (WSL) 1. **Ensure Windows 10 Professional/Enterprise, 64 Bit, Version &ge; 18.09**:<br/> Ensure you are running Windows 10 Professional or Windows 10 Enterprise in 64-bit mode and in Version 1809 (October 2018), 1903 (April 2019), 1909 (November 2019) or newer. > Rationale: Windows Subsystem for Linux (WSL) is available only > under those Windows editions, only under 64-bit and in a reasonable > fashion only under at least this version or newer. > Windows 10 in Version 1809 is the bare minimum. The recommended > system is Windows 10 in Version 1909. - *START* &rarr; *Settings* &rarr; *System* &rarr; *About*: - ... *Device Specifications* &rarr; *System type* - ... *Windows Specifications* &rarr; *Edition* - ... *Windows Specifications* &rarr; *Version* Notice: > If you have a different edition or you are running in 32-bit mode, > you are out of luck with WSL. Sorry, then you have to went with > [MSYS2](https://www.msys2.org/) or [Cygwin](https://www.cygwin.com/). > If you want to perform a fresh Windows 10 installation, start over with Microsoft's > [Download Windows 10 Disc Image (ISO File)](https://www.microsoft.com/en-us/software-download/windows10ISO/). > If you just still have an older Windows version, upgrade with one of the following > two options: > > - Windows Updates: *START* &rarr; `windows update settings` <kbd>RETURN</kbd> > - Windows Upgrades: [Windows 10 Update Assistant](https://www.microsoft.com/software-download/windows10) 2. **Enable Windows Subsystem for Linux**:<br/> Enable the Windows feature *Windows Subsystem for Linux*. > Rationale: Windows Subsystem for Linux is the core feature we want to use. - *START* &rarr; `powershell` &rarr; <kbd>RIGHT-CLICK</kbd> &rarr; *Run as administrator* - `Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux` Alternatively: - *START* &rarr; `control panel` &rarr; *Programs* &rarr; *Programs and Features* &rarr; *Turn Windows features on or off* &rarr; *Windows-Subsystem for Linux* > Notice: In case you have trouble to enable *Windows Subsystem for Linux*, this can have many reasons. > In most cases, the reason is that point (1) above is not exactly fulfilled. Start over there again. ## Install Ubuntu GNU/Linux Operating System 1. **Install Ubuntu 20.04 LTS**:<br/> Install Ubuntu GNU/Linux 20.04 Long Term Support (LTS) from the Microsoft Store. > Rationale: you need a reasonable GNU/Linux distribution and it should receive updates for a longer time. - *START* &rarr; `microsoft store` &rarr; *Search* &rarr; `ubuntu 20.04 lts` &rarr; *Get* &rarr; *Launch* Just be patient on first launch, it really takes time. Then, when asked for your username, enter the same as your Windows username. When asked for your password, enter either your Windows password or another one, but remember it (at least once until the step where we configure sudo(8) below)! > Notice: In case the Microsoft Store is not available on your system, the reason > can be that you still have User Account Control (UAC) disabled, or > you are still not signed in with a Microsoft Account (although it > should be not required), or your Windows is still not activated or > you are still running an evaluation version of Windows. Anyway, try > to fix the problems the following way: > > - *START* &rarr; *Settings* &rarr; *Updates & Security* &rarr; *Troubleshoot* &rarr; *Windows Store Apps* &rarr; *Run the troubleshooter* ## Setup Ubuntu GNU/Linux Operating System 1. **Enter Ubuntu under WSL**:<br/> Enter Ubuntu GNU/Linux under Windows Subsystem for Linux. > Rationale: we have to setup Ubuntu from itself. - *START* &rarr; *Ubuntu 20.04* 2. **Enable Convenient Root Access**:<br/> Ensure no password is needed for subsequent root access. > Rationale: just convenience only -- feel free to ignore if you want to enter your password over and over again. - `sudo vi /etc/sudoers`<br/> &larr; `%sudo ALL=(ALL:ALL) ALL`<br/> &rarr; `%sudo ALL=(ALL:ALL) NOPASSWD: ALL` 3. **Upgrade Ubuntu Operating System**:<br/> Upgrade to the latest package versions of Ubuntu and allow APT to use HTTPS. > Rationale: you always want the latest updates and Docker later needs HTTPS access. - `sudo apt-get update` - `sudo apt-get upgrade -y --with-new-pkgs` - `sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common` 4. **Mount Windows directories in WSL with Meta-Data enabled**:<br/> Configure the mounting of Windows directories in WSL (`/c` instead of `/mnt/c`) and with *Meta-Data* enabled. > Rationale: allow POSIX file permissions on Windows drives from within WSL. - `sudo vi /etc/wsl.conf`<br/> &rarr; `[automount]`<br/> &rarr; `enabled = true`<br/> &rarr; `root = /`<br/> &rarr; `options = "metadata,umask=022"` 5. **Use Combined Home Directory**:<br/> Map the Unix home directory to the regular Windows home directory. > Rationale: just convenience only -- feel free to ignore. - `exec sudo usermod -d /c/Users/$USER $USER` > Notice: Don't panic, we have to `exec` the command here to release the current user's processes > and this way let `usermod` proceed. This will immediately close the Unix terminal, of course. This step is a tricky one as the running WSL sub-process might not allow the changing of the underlying user home directory as long as it is running itself. One safe alternative is to execute the following command from within a CMD or PowerShell terminal: - `wsl sudo usermod -d /c/Users/%USERNAME% %USERNAME%` ## Configure Unix Shell Environment 1. **Re-Enter Ubuntu under WSL**:<br/> Re-Enter Ubuntu GNU/Linux under Windows Subsystem for Linux again. > Rationale: we have to configure the Unix environment from itself. - *START* &rarr; *Ubuntu 20.04* 2. **Install Essential Unix Tools**:<br/> Install all necessary essential and some more useful Unix tools. > Rationale: the subsequent Unix Shell Configurations are partially based on them and you really want a d