Bash terminal in Visual Studio Code on Windows

I primarily use Ubuntu whenever I need to code or work on a project. But sometimes, I have to code on Windows because I need some another software running alongside the editor. And I find it inconvenient to write code on Windows — the environment lacks ease, compatibility and customizations. Even for a single-file program, I have to create a project, configure the tools, and build it. This means I lose time when competing in online programming contests.

Thanks to Visual Studio Code, now I can at least participate in competitive programming contests while being on Windows 10. Visual Studio Code provides a modern customizable editor which comes with an integrated terminal panel. You can use PowerShell, Command Prompt or Bash in this terminal.

This post guides you through how to setup VS Code in Windows 10 with Ubuntu Bash terminal. You first need to have VS Code. If you don’t already have it, you can get it here. Once installed, you need to setup Ubuntu subsystem on Windows and then a little tweak in VS Code is all you need.

Setup Ubuntu Subsystem on Windows 10


For this you must be running 64-bit Windows 10 version 1607+. Ensure that you’re running the right version. You can check this under Settings > System > About.

win-set-about

Now switch to Developer Mode in Settings > Update & security > For developers.

win-dev-options

Next, enable Windows Subsystem for Linux (Beta) under Control Panel > Programs > Turn Windows features on or off.

ubuntu-subsystem

It will ask for system reboot. Go ahead and restart Windows.

After logging back into Windows, open Command Prompt, type bash and hit enter. This will take you through the installation process of Ubuntu subsystem. It might take some time to download the Ubuntu base depending on your internet connection. Once installation is over, it will ask you to choose username and password. Remember that this username and password in only for the Ubuntu subsystem and is independent of your Windows user account.

Now you should be able to run bash by using bash command in Command Prompt or PowerShell.

bash-on-cmd

There should also be a new program entry in your start menu — Bash on Ubuntu on Windows. Create its shortcut and you can directly run bash from there.

start-menu-bash-entry

Adding bash in VS Code


In VS Code, you can access the terminal in panel. To display the panel, go to View > Toggle Panel or you can use the shortcut Ctrl+J. But VS Code uses PowerShell as its default terminal.

vscode-terminal

You can change the terminal under File > Preferences > Settings. This will open the user settings file. It is a JSON file where editor settings are represented as a list of comma-separated properties. The left pane displays the list of properties and their default values. The right pane is where you have to put your custom settings.

vscode-settings

In the Default Settings pane, scroll down till you find Integrated Terminal setting section. Under this section, you have to look for "terminal.integrated.shell.windows" property. This property sets the default terminal in VS Code. By default its value is set to "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", which is the path of PowerShell in Windows.

vscode-default-terminal

You have to change this path to the path of bash in your system. Copy-paste the following code at the end the right pane (custom settings):

Ensure that all properties (except the last one) in custom settings have a comma at end.

vscode-ubuntu-bash

Save the file (Ctrl+S). And restart VS Code. Press Ctrl+J to toggle panel. And now you can use bash on VS Code.

vscode-bash-use

Happy coding!!

One thought to “Bash terminal in Visual Studio Code on Windows”

  1. Directly install ubuntu base without Windows store using command prompt using

    lxrun /install

    Super easy that way

Leave a Reply

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