68

I am currently using Windows 10 with WSL Ubuntu 18.04 installed. I am trying to use WSL as the default terminal in WebStorm however, I am able to use the bash from WSL but the default directory would not be set to the default project location.

Does anyone know how to set this up correctly?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
forkadam
  • 2,372
  • 2
  • 9
  • 17

11 Answers11

166

After a bit of search on google found a solution to my question.

First figure out the default wsl with the command:

C:\Windows\System32\wslconfig /list

Windows Subsystem for Linux Distributions:
Ubuntu-18.04 
Legacy (Default)

then I set the default to Ubuntu-18.04 by

C:\Windows\System32\wslconfig /setdefault Ubuntu-18.04

Finally set the terminal path in Webstrom settings>tools>terminal to

C:\Windows\System32\wsl.exe

Now open the terminal it is correctly move the current directory to the /mnt/c/blah/blah

forkadam
  • 2,372
  • 2
  • 9
  • 17
56

Set:
Settings > Tools > Terminal > Shell path

Equal to:

"C:\Users\<username>\AppData\Local\Microsoft\WindowsApps\ubuntu.exe" run

change setting


The result is:

resulting terminal

NonlinearFruit
  • 2,509
  • 1
  • 25
  • 27
  • 10
    I had to change it a bit for Ubuntu 20.04 like `"C:\Users\\AppData\Local\Microsoft\WindowsApps\ubuntu2004.exe" run` – severin.julien Jun 18 '20 at 18:08
  • 1
    alternatively one can put "ubuntu1804" instead of full shell path which will also work fine. – Denis O. Oct 12 '20 at 13:28
  • B.T.W why is this configured globally, as each project may have a different shell? Also, each project may have a different shell that should be allowed to be configured, one windows, one unix etc.. – Raja Nagendra Kumar Mar 25 '21 at 08:21
  • In the WSL, you can run Windows executables that are on your Windows path, as well as any Linux tools you might want. So I highly recommend using it by default everywhere. (As to why JetBrains doesn't allow for more granular control, I don't know) – NonlinearFruit Mar 25 '21 at 11:23
  • Im confused on why the hell everyones configurations are so different. Mine of none of these. This is complicated – numerical25 Mar 26 '21 at 15:53
  • @numerical25 maybe you need to install ubuntu first, take a look https://ubuntu.com/wsl – Germán Faller May 18 '21 at 11:41
19

Settings -> Tools -> Terminal change cmd.exe to C:\Windows\System32\bash.exe and restart Webstorm.

jabone
  • 389
  • 2
  • 13
  • 3
    It also works with `bash.exe` or the better `wsl.exe`. I personalized my terminal and the latest one gets my customization. – Gabrielizalo Apr 19 '20 at 22:39
15

For me the version was fetched and set automatically, after I opened a project located in \\wsl$\Ubuntu-20.04\home\my-user.

Webstorm set the shell path to wsl.exe --distribution Ubuntu-20.04

I use Webstorm version 2020.3 EAP currently

Akora
  • 756
  • 7
  • 22
  • 1
    This is the only updated answer the others are not wrong but are outdated. More here: https://blog.jetbrains.com/webstorm/2020/06/webstorm-2020-2-eap-3/ – Juan Rojas Nov 03 '20 at 09:41
  • Agree. The others arnt wrong but the exact path and different commands were never nessisay. – Brad Mar 10 '21 at 21:40
  • 3
    Worked for me, thanks bro, I use "wsl.exe --distribution Ubuntu" in "File -> Settings -> Tools -> Terminal ->Shell Path field". – Softmixt Mar 21 '21 at 18:44
7

You can just set your terminal to wsl no path required. Add --distribution to use another distro other than the default.

It's also automatic if you either, open a project from the distros own file system, or launch PHP storm from the terminal then the correct WSL distro will be used by the ide.

usernotnull
  • 3,480
  • 4
  • 25
  • 40
Brad
  • 741
  • 7
  • 17
5

Just adding an answer if you have multiple distros in your WSL and want to always use a particular one:

  1. Find out what WSL distros you have with wslconfig /list and identify the one you want to use (in my case it's "CentOS7")

enter image description here

  1. In your JetBrains product's Settings->Tools->Terminal, set the Shell path to wsl.exe --distribution <whatever distro you choose>. Example in CLion:

enter image description here

Click APPLY then OK.

Saeed Baig
  • 1,197
  • 12
  • 13
1

On Windows builds 16215 and higher:

  1. Install WSL and the Linux distro of your choice (I opted for Ubuntu 18.04)
    Windows support docs
  2. Switch the default terminal to bash
    Settings (or Default Settings)->Tools->Terminal->Shell path: bash

I use Webstorm and Rubymine and in my case, that was all that I had to do.

PS Please note that the Webstorm update 2018.2 finally brings in full integration of WSL for Node interpreter
Webstorm 2018.2 WSL

Also, Rubymine 2018.2 has drastically improved support for remote Ruby SDK (allows to use rvm), so now it is also super easy to use WSL/remote/containerized/dockerized Ruby env
Rubymine 2018.2 released

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Andrew
  • 2,309
  • 4
  • 27
  • 42
0

None of the above answers worked for me for default setting the terminal to zsh but this did

In phpstorm I have setup the setting of terminal shell path as bash.exe

Tool > Terminal

Shell Path: bash.exe

Then in the .bashrc I simply added the command at the end

/usr/bin/zsh

Now the terminal in phpstorm opens in zsh mode

Umutambyi Gad
  • 4,082
  • 3
  • 18
  • 39
0

I found excellent hint. You can not change default terminal. Use only 2 steps from post forkadam

First figure out the default wsl with the command:

C:\Windows\System32\wslconfig /list

Windows Subsystem for Linux Distributions:
Ubuntu-18.04 
Legacy (Default)

then I set the default to Ubuntu-18.04 by

C:\Windows\System32\wslconfig /setdefault Ubuntu-18.04

After it drag & drop folder which you want to use in terminal windows. In WebStorm you can use "open in terminal" from context menu, but in Rider only drag & drop for open in wsl terminal with special path.

0
  • set shell path enter image description here

  • edit Windows Terminal settings edit terminal settings

  • ALT + F12

nico1988
  • 63
  • 3
0

In my case, the 'Workspace trust' setting was also a factor: After following the above answers, I was still getting errors trying to start bash when I worked on WSL projects. Coincidentally, I was getting these 'Do you trust this workspace' prompts on IDE startup (WebStorm). Once I went to Settings|Build...| Trusted Locations and set the first entry to \\$wsl\Ubuntu-20.04\home\my-login-name my shell finally worked -- whodathunkit? :) HTH others - jps