Run linux bash in windows

4 Ways to Run Linux Commands in Windows

Brief: 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 personally you don’t have a Linux laptop but the 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 command 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

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2019/05/run-linux-commands-in-windows-300×169.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2019/05/run-linux-commands-in-windows-800×450.png» width=»800″ height=»450″ data-cfsrc=»https://itsfoss.com/wp-content/uploads/2019/05/run-linux-commands-in-windows-800×450.png» alt=»Run Linux Commands In Windows» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2019/05/run-linux-commands-in-windows.png 800w, https://itsfoss.com/wp-content/uploads/2019/05/run-linux-commands-in-windows-300×169.png 300w, https://itsfoss.com/wp-content/uploads/2019/05/run-linux-commands-in-windows-768×432.png 768w» data-lazy-sizes=»(max-width: 800px) 100vw, 800px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2019/05/run-linux-commands-in-windows-800×450.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″ style=»display:none;visibility:hidden;»>

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 of these methods for running Bash commands on Windows.

1. Use Linux Bash Shell on Windows 10

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.

You 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.

Linux distributions in Windows 10 Store

2. Use Git Bash to run Bash commands on Windows

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.

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2019/05/git-bash-300×211.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2019/05/git-bash.png» width=»677″ height=»476″ data-cfsrc=»https://itsfoss.com/wp-content/uploads/2019/05/git-bash.png» alt=»Git Bash» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2019/05/git-bash.png 677w, https://itsfoss.com/wp-content/uploads/2019/05/git-bash-300×211.png 300w» data-lazy-sizes=»(max-width: 677px) 100vw, 677px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2019/05/git-bash.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″ style=»display:none;visibility:hidden;»> Git Bash

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.

Читайте также:  Mustek bearpaw 1200cu plus linux mint

3. Using Linux commands in Windows with Cygwin

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.

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2019/05/cygwin-shell-300×152.jpg» data-large-file=»https://itsfoss.com/wp-content/uploads/2019/05/cygwin-shell.jpg» width=»669″ height=»338″ data-cfsrc=»https://itsfoss.com/wp-content/uploads/2019/05/cygwin-shell.jpg» alt=»Cygwin Shell» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2019/05/cygwin-shell.jpg 669w, https://itsfoss.com/wp-content/uploads/2019/05/cygwin-shell-300×152.jpg 300w» data-lazy-sizes=»(max-width: 669px) 100vw, 669px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2019/05/cygwin-shell.jpg?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″ style=»display:none;visibility:hidden;»> Cygwin | Image Credit

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 virtual machine

Another way is to use a virtualization software and install Linux in it. This way, you install a Linux distribution (with 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.

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2019/05/ubuntu-running-in-virtual-machine-inside-windows-300×169.jpeg» data-large-file=»https://itsfoss.com/wp-content/uploads/2019/05/ubuntu-running-in-virtual-machine-inside-windows-800×450.jpeg» width=»800″ height=»450″ data-cfsrc=»https://itsfoss.com/wp-content/uploads/2019/05/ubuntu-running-in-virtual-machine-inside-windows-800×450.jpeg» alt=»Ubuntu Running In Virtual Machine Inside Windows» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2019/05/ubuntu-running-in-virtual-machine-inside-windows.jpeg 800w, https://itsfoss.com/wp-content/uploads/2019/05/ubuntu-running-in-virtual-machine-inside-windows-300×169.jpeg 300w, https://itsfoss.com/wp-content/uploads/2019/05/ubuntu-running-in-virtual-machine-inside-windows-768×432.jpeg 768w» data-lazy-sizes=»(max-width: 800px) 100vw, 800px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2019/05/ubuntu-running-in-virtual-machine-inside-windows-800×450.jpeg?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″ style=»display:none;visibility:hidden;»> Ubuntu Running in Virtual Machine Inside Windows

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.

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.

Creator of It’s FOSS. An ardent Linux user & open source promoter. Huge fan of classic detective mysteries ranging from Agatha Christie and Sherlock Holmes to Detective Columbo & Ellery Queen. Also a movie buff with a soft corner for film noir.

Источник

How to Install Linux Bash Shell on Windows 10

Brief: This beginner’s tutorial shows you how to install bash on Windows.

Linux on Windows is a reality, thanks to the partnership between Canonical (parent company of Ubuntu) and Microsoft. When Microsoft’s CEO announced that the Bash shell was coming to Windows, a number of people just couldn’t believe it. #BashOnWindows trended on Twitter for days, such was the impact of this news.

But Bash on Windows was not available to everyone immediately. People had to install the Windows 10 technical preview to install Linux on Windows 10. But this is not the case anymore. The Windows 10 anniversary upgrade is here and now you can easily get Bash on Windows. And, before we go on installing Bash on Windows, let me tell you a little more about it.

Note: This tutorial was tested with the latest available Windows 10 version 2004 and build 19041.450. You might need to update your Windows installation if you’ve an older build to follow everything in this tutorial.

What is Bash on Windows?

Bash on Windows provides a Windows subsystem and Ubuntu Linux runs atop it. It is not a virtual machine or an application like Cygwin. It is complete Linux system inside Windows 10.

Basically, it allows you to run the same Bash shell that you find on Linux. This way you can run Linux commands inside Windows without the needing to install a virtual machine, or dual boot Linux and Windows. You install Linux inside Windows like a regular application. This is a good option if your main aim is to learn Linux/Unix commands.

I recommend reading this article to know more about Bash on Windows.

Method 1: Install Linux Bash Shell on Windows 10 Newer Versions

Good thing is that the Fall Creator’s Update and the recent Windows 10, version 2004 makes it easier to install Bash on Windows 10. You can get it in one click from Windows Store. There are still a few things to do however.

I am installing Ubuntu using Windows Subsystem for Linux. You can also use SUSE Linux. The procedure is same for both distributions.

Step 1: Enable “Windows Subsystem for Linux” feature

The first thing you need to do is to enable Windows Subsystem for Linux feature from PowerShell or from the Windows feature options.

Читайте также:  Запуск windows приложений под astra linux

If you want to utilize the GUI, you can simply search for option to get the list of Windows features to enable a few things as shown in the screenshot below.

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features-300×240.jpg» data-large-file=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features.jpg» width=»800″ height=»639″ src=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features.jpg» alt=»Windows Features» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features.jpg 800w, https://itsfoss.com/wp-content/uploads/2020/08/windows-features-300×240.jpg 300w, https://itsfoss.com/wp-content/uploads/2020/08/windows-features-768×613.jpg 768w» data-lazy-sizes=»(max-width: 800px) 100vw, 800px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features.jpg?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Windows Features option

Now, you just have to open it to access all the options. Among the ones listed, you have to enable (or check) the feature for “Windows Subsystem for Linux” and “Virtual Machine Platform” and then perform a reboot to make sure you have both of them enabled.

Windows Features Subsystem Virtual Option

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features-subsystem-virtual-option-300×226.jpg» data-large-file=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features-subsystem-virtual-option.jpg» width=»800″ height=»603″ src=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features-subsystem-virtual-option.jpg» alt=»Windows Features Subsystem Virtual Option» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features-subsystem-virtual-option.jpg 800w, https://itsfoss.com/wp-content/uploads/2020/08/windows-features-subsystem-virtual-option-300×226.jpg 300w, https://itsfoss.com/wp-content/uploads/2020/08/windows-features-subsystem-virtual-option-768×579.jpg 768w» data-lazy-sizes=»(max-width: 800px) 100vw, 800px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2020/08/windows-features-subsystem-virtual-option.jpg?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″>

In either case, if you want to utilize the PowerShell, you can just go to the Start menu and search for PowerShell. Run it as administrator:

Once you have the PowerShell running, use the command below to enable Bash in Windows 10.

You’ll be asked to confirm your choice. Type Y or press enter:

Now you should be asked to reboot. Even if you are not asked to, you must restart your system.

Step 2: Download a Linux system from the Windows store

Once your system has rebooted, go to the Windows Store and search for “Linux” or just “Ubuntu”.

You’ll see the option to install Ubuntu or SUSE. I have installed Ubuntu for Bash on Windows here.

What’s the difference between using Ubuntu or openSUSE or SUSE Linux Enterprise? And which one should you use?

To tell you quickly, the main difference would be in the commands for installing new packages inside these Linux subsystems. I advise going for Ubuntu in this case.

Once you choose the distribution of your choice, you’ll see the option to install it. Do note that it will download files of around 1Gb in size or less depending on what you’re downloading.

Step 3: Run Linux inside Windows 10

You are almost there. Once you have installed Linux, it’s time to see how to access Bash in Windows 10.

Just search for the Linux distribution you installed in the previous step. In my case it was Ubuntu. You’ll see that it runs like a normal Windows application.

It will take some time installing and then you’ll have to set up the username and password.

Don’t worry, it’s just for the first run. Bash shell will be available for use directly from the next time onwards.

Enjoy Linux inside Windows 10.

Troubleshooting 1: The WSL optional component is not enabled. Please enable it and try again.

You may see an error like this when you try to run Linux inside Windows 10:

And when you press any key, the application closes immediately.

The reason here is that the Windows Subsystem for Linux is not enabled in your case. You should enable it as explained in step 1 of this guide. You can do that even after you have installed Linux from Windows Store.

Troubleshoot 2: Installation failed with error 0x80070003

This is because Windows Subsystem for Linux only runs on the system drive i.e. the C drive. You should make sure that when you download Linux from the Windows Store, it is stored and installed in the C Drive.

Go to Settings -> Storage -> More Storage Settings: Change where new content is saved and select C Drive here.

Method 2: Install Linux Bash Shell on older Windows 10

If you cannot get the Fall Creator’s update on Windows 10 for some reason, you can still install it if you have the Anniversary update of Windows 10. But here, you’ll have to enable developer mode. I still recommend upgrading to the Fall Creator’s update or the latest Windows 10 2004 version update though.

Step 1:

Press Windows Key + I to access Windows system settings. In here, go to Update & Security:

Step 2:

From the left side pane, choose “For developers.” You’ll see an option for “Developer mode.” Enable it.

Step 3:

Now search for Control Panel and in Control Panel, click on “Programs”:

Step 4:

In Programs, click “Turn Windows features on or off”:

Читайте также:  Zbr failure что за ошибка

Step 5:

When you do this, you’ll see several Windows features. Look for “Windows Subsystem for Linux” and enable it.

Step 6:

You’ll need to restart the system after doing this.

Step 7:

After restarting the computer, click the start button and search for “bash”.

Step 8:

When you run it for the first time, you’ll be given the option to download and install Ubuntu. You’ll be asked to create a username and password during this process. It will install an entire Ubuntu Linux system, so have patience as it will take some time in downloading and installing Linux on Windows.

Step 9:

Once this is done, go back to the Start menu and search for Ubuntu or Bash.

Step 10:

Now you have a command line version of Ubuntu Linux. You can use apt to install various command line tools in it.

Bonus Tip: Run GUI Apps On Windows Subsystem for Linux

The ability to run GUI apps on Windows Subsystem for Linux was introduced with WSL 2 release in May 2020.

It’s still not something officially supported out-of-the-box, but if you’re curious, you can experiment with it by following the steps below:

Step 1: Enable/Update WSL 2

If you have the latest Windows version 2004, build 19041, you already have WSL 2 support but you need to enable it and set it to default instead of WSL 1.

To do that, first you need to ensure that you have the latest WSL 2 Linux Kernel by updating the WSL 2 Linux Kernel.

You just need to follow the instructions on the official documentation page and download/install the package. Once done, you need to launch the PowerShell (run it as administrator) and set WSL 2 as the default by typing the following command:

You should get a message that says “For information on key differences with WSL 2 please visit https://aka.ms/wsl2”.

In case you get an error (Error: 0x1bc), you need to make sure that you have updated the WSL 2 Linux Kernel, that solved the issue for me.

Step 2: Download and Install a Windows X Server Program

As I mentioned, WSL 2 does not have the official support for running GUI apps by default. So, to do it, we need to download and install a Windows X Server program to give WSL access to display the apps.

You can try the open-source XLaunch server that we’re using here.

Step 3: Configure Windows X Server

Now that you have installed it, you just need to configure a few things.

First, Launch XLaunch and proceed to ensure that you have the following options enabled:

1. Keep the Display number set as -1 and select “Multiple Windows

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-3-300×225.jpg» data-large-file=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-3.jpg» width=»800″ height=»599″ src=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-3.jpg» alt=»Xlaunch Options 3″ data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-3.jpg 800w, https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-3-300×225.jpg 300w, https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-3-768×575.jpg 768w» data-lazy-sizes=»(max-width: 800px) 100vw, 800px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-3.jpg?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Xlaunch Options 3

2. Next, you need to enable “Start no client“.

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-1-300×225.jpg» data-large-file=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-1.jpg» width=»800″ height=»599″ src=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-1.jpg» alt=»Xlaunch Options 1″ data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-1.jpg 800w, https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-1-300×225.jpg 300w, https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-1-768×575.jpg 768w» data-lazy-sizes=»(max-width: 800px) 100vw, 800px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-1.jpg?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″>

3. Finally, you just need to check “Disable access control” to avoid permission issues and save the configuration on the next step to complete the configuration.

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-2-300×218.jpg» data-large-file=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-2.jpg» width=»800″ height=»582″ src=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-2.jpg» alt=»Xlaunch Options 2″ data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-2.jpg 800w, https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-2-300×218.jpg 300w, https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-2-768×559.jpg 768w» data-lazy-sizes=»(max-width: 800px) 100vw, 800px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2020/08/xlaunch-options-2.jpg?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″>

Now everything’s almost done, you need to launch Ubuntu from the list of apps installed and configure it to launch Linux GUI apps on Windows.

Just enter the following command in the Linux terminal (Ubuntu):

Now, just install your favorite Linux GUI app from the terminal and test if it works! In my case, I installed and launched Gedit using the following commands:

And, here’s how it looks:

» data-medium-file=»https://itsfoss.com/wp-content/uploads/2020/08/gedit-wsl-2-300×119.jpg» data-large-file=»https://itsfoss.com/wp-content/uploads/2020/08/gedit-wsl-2.jpg» width=»800″ height=»316″ src=»https://itsfoss.com/wp-content/uploads/2020/08/gedit-wsl-2.jpg» alt=»Gedit Wsl 2″ data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2020/08/gedit-wsl-2.jpg 800w, https://itsfoss.com/wp-content/uploads/2020/08/gedit-wsl-2-300×119.jpg 300w, https://itsfoss.com/wp-content/uploads/2020/08/gedit-wsl-2-768×303.jpg 768w» data-lazy-sizes=»(max-width: 800px) 100vw, 800px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2020/08/gedit-wsl-2.jpg?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″>

I hope you find this tutorial helpful for installing bash on Windows 10 and experimenting Linux GUI apps on Windows 10. No wonder WSL lets you play with Linux inside of Windows. If you have questions or suggestions, feel free to ask.

Creator of It’s FOSS. An ardent Linux user & open source promoter. Huge fan of classic detective mysteries ranging from Agatha Christie and Sherlock Holmes to Detective Columbo & Ellery Queen. Also a movie buff with a soft corner for film noir.

Источник

Поделиться с друзьями
КомпСовет
Adblock
detector