All to the Windows subsystem for Linux 2

This instruction shows how to install, manage, and use a complete Linux environment on your Windows 10 PC with WSL2. You will run a Linux kernel and run local programs while sharing files seamlessly and with Windows code editors and browsers.

Your host almost uses Linux. It is fast, open source and runs most Internet software, which includes:

Some of those dependencies may have on Windows and macOS, however, installing and maintaining the same versions is difficult. They are slower and possibly revel in sophisticated differences that might not appear before deployment.

Some developers install Linux on their desktop, but this may not be feasible if you want non-Linux software, such as Microsoft or Adobe products. Alternative options:

The Windows Linux (WSL) subsystem allows developers to run a Linux environment on Windows 10. It is an operating system without modification, but highly incorporated with Windows and without the overhead of a virtual machine.

WSL1, revolutionary Linux formula calls and translated to Windows equivalents. This can be slow and several functions are not available. WSL2 uses Hyper-V virtual device technology, so Linux support is perfect and access to logs is up to 20 times faster than before.

WSL2 is compatible with Windows Home, Pro, or Server editions, but not Windows 10 S (although you can upgrade to Home Edition for free).

The May 2020 Windows update is a must: it’s edition 2004 or higher. Choose the setup gear from the Start menu, then System and then About. Windows specifications are displayed on the back of the panel:

The update has been rolling slowly since late May 2020. If you have an edition less than 2004, you may need to perform the update by clicking the Check for Updates button in Settings, then Update and Security.

If 2004 is still stubbornly useless, you may need to download and install it manually from microsoft.com/software-download/windows10

Note, however, that some PCs report that the 2004 edition is not available lately in the Windows Update dashboard. You may not be able to upgrade until Microsoft has released a solution for your device.

WSL2 (and Hyper-V) require hardware virtualization to be enabled in your BIOS.

Hardware virtualization will be active on maximum devices, but you can verify by restarting and opening the BIOS panels, via the urgent LED, F2, or F10 button when the formula starts. Look for virtualization technology, VTx, or similar options. Make sure they are turned on, save and restart the device.

Finally, make sure that your C: drive has at least 1 GB of available disk area, preferably more. You may lose space in your configuration, system, garage, or disk cleanup tool in Windows management tools.

At the time of writing, WSL2 will install Linux on your C:, although it is possible to move it elsewhere after installation.

The virtual device platform and Windows for Linux subsystem features must be enabled under Enable or disable Windows features. The panel is available by tapping Start and typing “features” or from the Programs and Features icon in the old settings panel.

You can run the following commands on a Windows Powershell terminal that runs as an administrator:

Restart Windows 10, then turn on WSL2 by default by entering the following command in Windows PowerShell or at the command prompt:

You can install any number of Linux distributions from the Microsoft Store found in the Start menu. This includes Ubuntu, Debian, SUSE, Kali and Alpine. Enter “Linux” in the search field:

Ubuntu is an option, unless you have express requirements. The latest edition will be installed if you click the Ubuntu icon and then the Get button.

The download may take some time depending on the speed of your network.

After the download, click the Start button in the Microsoft Store app or the new Ubuntu icon in the Start menu. This will complete the installation procedure and possibly take several minutes.

You will be prompted to enter a username and password. These are the credentials for Linux administration: they are absolutely independent of your Windows username and password (although you may want to opt for the same).

Linux will still be in one position and your device will demonstrate content similar to this:

There will be several Linux updates. To upgrade Ubuntu, enter the following commands in the Linux terminal:

Other Linux distributions will have a process, but refer to the documentation for help.

Existing WSL1 distributions can be changed to WSL2. Enter the following command in a Windows Powershell terminal to view the Linux distributions and their WSL version:

(The asterisk: Highlights the default Linux installation).

To transfer Ubuntu to WSL2, enter:

Similarly, in order to return to WSL1, enter:

When multiple Linux distributions are installed, one must be configured by default. It will be used when wsl has entered a Windows Powershell terminal.

To set the default distribution, your installations:

and set a default value with:

Ubuntu example: wsl –setdefault Ubuntu.

A default user is set during installation and you can create more. A root user is also created, but it deserves to be avoided in general circumstances. It’s too simple to enter a harmful command!

The Linux disk image is installed on your C: drive. Optionally, you can move it to another drive to free up space. The following instructions presume you’ll move it to D:wsl.

In a Windows Powershell terminal (not in the Ubuntu terminal), enter wsl –list to view your Linux distributions, then export one through a call to a backupArraytar file, for example. D: ‘backup’ and ubuntu.tar:

Save the same distribution from drive C:

Enter wsl –list for the distribution to be deleted.

Import the backup to a new WSL2 distribution in the location, such as D:Wsl:

Make sure that it has been created effectively by entering wsl –list and launching the Ubuntu application from the Start menu.

Unfortunately, Ubuntu will now use root as the default user. To use your account, enter the following command:

Where is the username you set when you did it?

Assuming everything went well, you can safely delete the backup log (D: backup – ubuntu.tar).

To release the Linux device, you can use the Ubuntu icon, enter wsl or bash in Powershell, or use any third-party options like Cmder, ConEmu or Hyper. Profiles can be configured to release windir – system32 – bash.exe.

Another option is Windows Terminal, which is also available in the Microsoft Store or its repository in github.com/microsoft/terminal/.

Windows Terminal will load your Linux WSL2 distributions and offer a variety of highly configurable options, adding tabs, split views, themes, transparency and keyboard shortcuts.

The options are set in the settings.json file, which can be accessed from the Settings or Ctrl menu. The default and theme settings can be displayed in defaults.json, available by holding down the Alt key while the Settings menu is clicked.

Linux logs are available in the network path – wsl $. This can be entered in the log explorer’s front bar or in any log-opening conversation box.

Your installed Linux distributions are listed, so you can access the Ubuntu root directory in ‘wsl $’ – Ubuntu. Your non-public Linux files will be stored in:

It is for use as an initial folder in the Windows terminal. Open the configuration and load the following configuration line into the Ubuntu profile:

Where is the username you set when you did it?

You can mount a network reader in ‘wsl$ Ubuntu’ by opening ‘wsl$’ in File Explorer, right-clicking on the Ubuntu folder and opting to Map the Network Player…

Unfortunately, lately it is not imaginable to map a deeper sub-repertoire. Possibly you would also delight in drive disorders mapped with some applications.

Windows players are fixed on Linux/mnt/. For example, your Personal Users in folder C: ‘Users’ must be in:

For ease of access, you can create a symbolic link to any Windows folder from Ubuntu terminal, for C: ‘projects’ and ‘code’:

A code folder appears in your nonpublic directory. Access it using CD/code and are actually in /mnt/c/projects/code/, which corresponds directly to the code C: ‘projects’.

Any Linux shell command (bash) can be run from Windows Powershell or from a wsl command-line terminal:

For example: wsl: Lists the full contents and main points of files in a Windows folder.

Any Windows executable can be launched from Linux (it’s normally necessary to specify the .exe extension). For example, to open the current Linux directory in File Explorer, enter:

or edit, bashrc in the Notebook:

or open the directory of a map in VS Code:

Never use two operating systems. They can be highly integrated, but there are conditions where you need an application to be installed on one or both.

It might be convenient to use Git on Windows or Linux. The Windows edition is installed by downloading an executable, but Git on Ubuntu is installed using:

Similarly, you may need to verify Node.js applications on Windows and Linux. Again, Windows has an installation program, but Node.js 14.x is installed in Ubuntu commands:

The git, node, and npm commands will now paint in environments.

One exception to the “install twice” rule is Docker.

Docker runs programs on remote Linux boxes that are conceptually similar to lightweight virtual machines with an operating system, single application, and its dependencies. Using Docker for Internet progression provides a consistent environment that is easy to install and works on any device.

Docker Desktop for Windows supports WSL2:

Docker will use the default Linux distribution, but you can also enable it on other installed distributions from the WSL Integration pane under Settings, and then under Resources.

Internet dependencies such as Apache and PHP can be installed directly in your WSL2 Linux environment. However, Docker is more secure, faster, and more configurable: it allows you to run other versions of PHP on the same device at the same time.

In this example, create a small PHP record and run it using the latest edition of PHP 7.4 in a Docker container. Make sure that you have installed Docker Desktop for Windows and enabled WSL2 mode, and then create a folder in your Linux environment with an index.php registry. Like what:

Change index.php, maybe Notepad or VS Code as shown above. Add the following content that generates data about PHP prestige:

Run the following docker command to start a PHP 7.4-compatible Apache Internet server in a container that mounts the host directory files to /var/www/html in the container:

Note: This command would also work on Windows, the reference to $PWD deserves to be replaced via full registry in Linux notation, for example /c/php/.

Open https://localhost:8080/ in any Windows web browser to view the output generated by your PHP file:

Finally, press Ctrl-C on your Docker terminal to prevent and delete the container.

Applications running on Windows, WSL2 Linux, and Docker Box are still available from the host or 127.0.0.1.

The PHP example above exposed port 8080, which was mapped to port 80 in the container. Similarly, if you have Node.js installed in Linux, you can cd to any directory and start a static file server:

Note that ports that are taken in one operational formula may not be taken in the other. Port 80 is reserved through the Skype Windows 10 application and cannot be replaced (although the old desktop edition allows it).

Self-signed or locally approved SSL certificate computers, such as mkcert, can be used interchangeably in Windows and Linux environments.

The WSL2 shell can be chosen as the default VS Code terminal by pressing Ctrl + Shift + P and typing/choosing Terminal: Select Default Shell, then selecting WSL Bash:

Like other applications, VS Code can Linux files directly in ‘wsl$’ and debugs running on localhost. No more extensions are required, but the following features make it less difficult to manage Linux and Docker files:

After installing Remote – WSL, you can use any Linux directory and launch an example of VS Code connected to WSL:

You can also click the remote window icon on the left back of the application and then on a connection option:

Or use the new Remote Explorer icon in the activity bar. This allows you to select a target type from the drop-down list and log in accordingly:

The remote VS Code sample has a separate set of extensions and configurations for Linux use. This allows debugging of WSL2 code and is convenient when you have a combination of execution languages installed in any of the operational formulas, you should not have an extension in a formula or when other operational formula configurations are required.

The Extensions pane must enable and configure extensions on the remote instance:

The configuration is in your Linux ArrayArrayArray directory

WSL2 will revolutionize your Internet development. This makes it less difficult to write code using Windows computers and then run it in a Linux environment. While it was imaginable in the past with virtual machines and Samba folder sharing, WSL2 provides a simpler, faster, and highly built-in experience.

Other resources:

© 2000-2020 SitePoint Pty.Ltd.

This site is through reCAPTCHA and Google’s privacy policy and terms of use apply.

Leave a Comment

Your email address will not be published. Required fields are marked *