Linux cli on windows

Install Linux on Windows with WSL

Developers can access the power of both Windows and Linux at the same time on a Windows machine. The Windows Subsystem for Linux (WSL) lets developers install a Linux distribution (such as Ubuntu, OpenSUSE, Kali, Debian, Arch Linux, etc) and use Linux applications, utilities, and Bash command-line tools directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup.

Prerequisites

You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 to use the commands below. If you are on earlier versions please see the manual install page.

Install WSL command

You can now install everything you need to run WSL with a single command. Open PowerShell or Windows Command Prompt in administrator mode by right-clicking and selecting «Run as administrator», enter the wsl —install command, then restart your machine.

This command will enable the features necessary to run WSL and install the Ubuntu distribution of Linux. (This default distribution can be changed).

If you’re running an older build, or just prefer not to use the install command and would like step-by-step directions, see WSL manual installation steps for older versions.

The first time you launch a newly installed Linux distribution, a console window will open and you’ll be asked to wait for files to de-compress and be stored on your machine. All future launches should take less than a second.

The above command only works if WSL is not installed at all, if you run wsl —install and see the WSL help text, please try running wsl —list —online to see a list of available distros and run wsl —install -d to install a distro. To uninstall WSL, see Uninstall legacy version of WSL or unregister or uninstall a Linux distribution.

Change the default Linux distribution installed

By default, the installed Linux distribution will be Ubuntu. This can be changed using the -d flag.

  • To change the distribution installed, enter: wsl —install -d . Replace with the name of the distribution you would like to install.
  • To see a list of available Linux distributions available for download through the online store, enter: wsl —list —online or wsl -l -o .
  • To install additional Linux distributions after the initial install, you may also use the command: wsl —install -d .

If you want to install additional distributions from inside a Linux/Bash command line (rather than from PowerShell or Command Prompt), you must use .exe in the command: wsl.exe —install -d or to list available distributions: wsl.exe -l -o .

If you run into an issue during the install process, check the installation section of the troubleshooting guide.

To install a Linux distribution that is not listed as available, you can import any Linux distribution using a TAR file. Or in some cases, as with Arch Linux, you can install using an .appx file. You can also create your own custom Linux distribution to use with WSL.

Читайте также:  Linux execute file command line

Set up your Linux user info

Once you have installed WSL, you will need to create a user account and password for your newly installed Linux distribution. See the Best practices for setting up a WSL development environment guide to learn more.

Set up and best practices

We recommend following our Best practices for setting up a WSL development environment guide for a step-by-step walk-through of how to set up a user name and password for your installed Linux distribution(s), using basic WSL commands, installing and customizing Windows Terminal, set up for Git version control, code editing and debugging using the VS Code remote server, good practices for file storage, setting up a database, mounting an external drive, setting up GPU acceleration, and more.

Check which version of WSL you are running

You can list your installed Linux distributions and check the version of WSL each is set to by entering the command: wsl -l -v in PowerShell or Windows Command Prompt.

To set the default version to WSL 1 or WSL 2 when a new Linux distribution is installed, use the command: wsl —set-default-version , replacing with either 1 or 2.

To set the default Linux distribution used with the wsl command, enter: wsl -s or wsl —setdefault , replacing with the name of the Linux distribution you would like to use. For example, from PowerShell/CMD, enter: wsl -s Debian to set the default distribution to Debian. Now running wsl npm init from Powershell will run the npm init command in Debian.

To run a specific wsl distribution from within PowerShell or Windows Command Prompt without changing your default distribution, use the command: wsl -d , replacing with the name of the distribution you want to use.

Learn more in the guide to Basic commands for WSL.

Upgrade version from WSL 1 to WSL 2

New Linux installations, installed using the wsl —install command, will be set to WSL 2 by default.

The wsl —set-version command can be used to downgrade from WSL 2 to WSL 1 or to update previously installed Linux distributions from WSL 1 to WSL 2.

To see whether your Linux distribution is set to WSL 1 or WSL 2, use the command: wsl -l -v .

To change versions, use the command: wsl —set-version 2 replacing with the name of the Linux distribution that you want to update. For example, wsl —set-version Ubuntu-20.04 2 will set your Ubuntu 20.04 distribution to use WSL 2.

If you manually installed WSL prior to the wsl —install command being available, you may also need to enable the virtual machine optional component used by WSL 2 and install the kernel package if you haven’t already done so.

To learn more, see the Command reference for WSL for a list of WSL commands, Comparing WSL 1 and WSL 2 for guidance on which to use for your work scenario, or Best practices for setting up a WSL development environment for general guidance on setting up a good development workflow with WSL.

Ways to run multiple Linux distributions with WSL

WSL supports running as many different Linux distributions as you would like to install. This can include choosing distributions from the Microsoft Store, importing a custom distribution, or building your own custom distribution.

There are several ways to run your Linux distributions once installed:

  • Install Windows Terminal(Recommended) Using Windows Terminal supports as many command lines as you would like to install and enables you to open them in multiple tabs or window panes and quickly switch between multiple Linux distributions or other command lines (PowerShell, Command Prompt, PowerShell, Azure CLI, etc). You can fully customize your terminal with unique color schemes, font styles, sizes, background images, and custom keyboard shortcuts. Learn more.
  • You can directly open your Linux distribution by visiting the Windows Start menu and typing the name of your installed distributions. For example: «Ubuntu». This will open Ubuntu in it’s own console window.
  • From Windows Command Prompt or PowerShell, you can enter the name of your installed distribution. For example: ubuntu
  • From Windows Command Prompt or PowerShell, you can open your default Linux distribution inside your current command line, by entering: wsl.exe .
  • From Windows Command Prompt or PowerShell, you can use your default Linux distribution inside your current command line, without entering a new one, by entering: wsl [command] . Replacing [command] with a WSL command, such as: wsl -l -v to list installed distributions or wsl pwd to see where the current directory path is mounted in wsl. From PowerShell, the command get-date will provide the date from the Windows file system and wsl date will provide the date from the Linux file system.
Читайте также:  Rpm based linux системы

The method you select should depend on what you’re doing. If you’ve opened a WSL command line within a Windows Prompt or PowerShell window and want to exit, enter the command: exit .

Want to try the latest WSL preview features?

Try the most recent features or updates to WSL by joining the Windows Insiders Program. Once you have joined Windows Insiders, you can choose the channel you would like to receive preview builds from inside the Windows settings menu to automatically receive any WSL updates or preview features associated with that build. You can choose from:

  • Dev channel: Most recent updates, but low stability.
  • Beta channel: Ideal for early adopters, more reliable builds than the Dev channel.
  • Release Preview channel: Preview fixes and key features on the next version of Windows just before its available to the general public.

Additional resources

Источник

4 Ways to Run Linux Commands in Windows

Want to use Linux commands but don’t want to leave Windows? Here are several ways to run Linux bash commands in Windows.

If you are learning Shell scripting probably as a part of your course curriculum, you need to use Linux commands to practice the commands and scripting. Your school lab might have Linux installed but you don’t have a Linux laptop but a regular Windows computer like everyone else. Your homework needs to run Linux commands and you wonder how to run Bash commands and scripts on Windows. You can install Linux alongside Windows in dual boot mode. This method allows you to choose either Linux or Windows when you start your computer. But taking all the trouble to mess with partitions for the sole purpose of running Linux commands may not be for everyone. You can also use Linux terminals online but your work won’t be saved here. The good news is that there are several ways you can run Linux commands inside Windows, like any regular application. Isn’t it cool?

Using Linux commands inside Windows

Run Linux Commands In Windows

As an ardent Linux user and promoter, I would like to see more and more people using ‘real’ Linux but I understand that at times, that’s not the priority. If you are just looking to practice Linux to pass your exams, you can use one method to run Bash commands on Windows.

Читайте также:  Загружается начальный виртуальный диск linux

1. Use Linux Bash Shell on Windows 10 with WSL

Did you know that you can run a Linux distribution inside Windows 10? The Windows Subsystem for Linux (WSL) allows you to run Linux inside Windows. The upcoming version of WSL will be using the real Linux kernel inside Windows. This WSL, also called Bash on Windows, gives you a Linux distribution in command-line mode running as a regular Windows application. Don’t be scared with the command line mode because your purpose is to run Linux commands. That’s all you need. Using Bash on Windows 10You can find some popular Linux distributions like Ubuntu, Kali Linux, openSUSE etc in Windows Store. You just have to download and install it like any other Windows application. Once installed, you can run all the Linux commands you want. Install Windows Subsyetm for LinuxPlease refer to this tutorial about installing Linux bash shell on Windows.

2. Use Git Bash to run Bash commands on Windows

Git Bash

You probably know what Git is. It’s a version control system developed by Linux creator Linus Torvalds. Git for Windows is a set of tools that allows you to use Git in both command line and graphical interfaces. One of the tools included in Git for Windows is Git Bash. Git Bash application provides and emulation layer for Git command line. Apart from Git commands, Git Bash also supports many Bash utilities such as ssh, scp, cat, find etc. In other words, you can run many common Linux/Bash commands using the Git Bash application. You can install Git Bash in Windows by downloading and installing the Git for Windows tool for free from its website.

3. Using Linux commands in Windows with Cygwin

Cygwin Shell

If you want to run Linux commands in Windows, Cygwin is a recommended tool. Cygwin was created in 1995 to provide a POSIX-compatible environment that runs natively on Windows. Cygwin is a free and open source software maintained by Red Hat employees and many other volunteers. For two decades, Windows users use Cygwin for running and practicing Linux/Bash commands. Even I used Cygwin to learn Linux commands more than a decade ago. You can download Cygwin from its official website below. I also advise you to refer to this Cygwin cheat sheet to get started with it.

4. Use Linux in a virtual machine

Ubuntu Running In Virtual Machine Inside Windows

Another way is to use virtualization software and install Linux in it. This way, you install a Linux distribution (with a graphical interface) inside Windows and run it like a regular Windows application. This method requires that your system has a good amount of RAM, at least 4 GB but better if you have over 8 GB of RAM. The good thing here is that you get the real feel of using a desktop Linux. If you like the interface, you may later decide to switch to Linux completely. There are two popular tools for creating virtual machines on Windows, Oracle VirtualBox and VMware Workstation Player. You can use either of the two. Personally, I prefer VirtualBox. You can follow this tutorial to learn how to install Linux in VirtualBox.

Conclusion

The best way to run Linux commands is to use Linux. When installing Linux is not an option, these tools allow you to run Linux commands on Windows. Give them a try and see which method is best suited for you.

Источник

Оцените статью
Adblock
detector