7

I am trying to make a shortcut for Firefox from WSL2 to Windows 10 Home, but I haven't been able to do so. I am using VcXsrv, which I've set to automatically start. I can't use WSLg since I'm not on Windows 11.

Can you use apps, like Firefox, in a Windows shortcut without having to export DISPLAY manually?

4
  • 2
    FYI: There is no supported unexpired build of Windows 10 that supports WSLg it's currently only a feature of Windows 11. The only builds of Windows 10 that supported it, are now expired Insider Preview builds, that can't honestly be used since they are expired.
    – Ramhound
    Commented May 31, 2022 at 12:03
  • Please don’t add descriptions like “outdated” to your question title.
    – Ramhound
    Commented Jan 8, 2023 at 0:32
  • If you believe it is outdated, then create a new answer with up-to-date info. And while you may no longer need this solution, others may still find useful information in it in the future. Commented Jan 8, 2023 at 16:45
  • @Mohab13 Sure, but the question was about how to do it with VcXsrv, which is still used by some people in place of WSLg. Like Ramhound said, we just don't put "Outdated" in the title here. Commented Jan 8, 2023 at 20:55

4 Answers 4

11

It sounds like you:

  • Already have your DISPLAY variable set up properly and can run Firefox from the commandline in VcXsrv. That's a great start.

  • Don't yet have the DISPLAY variable exported in ~/.bashrc, since you mention having to export it manually.

If that's the case, then you'll first need to export the variable in your startup config. If you have already done this part, skip to the "Shortcut commandline" section below.

Export DISPLAY in startup

Add the following to your ~/.bashrc:

export DISPLAY="$(hostname).local:0"

That uses mDNS to pick up the proper IP address based on my answer here on the topic. If you have another DISPLAY setting that works for you, you can use it instead, but I find the hostname based approach the easiest in most cases.

Then:

source ~/.bashrc

to have it re-read the configuration. You could also restart the shell to make sure. Then make sure Firefox runs.

Shortcut commandline

The above works when you are in an interactive shell, since the rc file is sourced for interactive shells. However, when you are launching Firefox via a shortcut, you'll need to use the wsl.exe command, and by default that isn't an interactive (or login) shell.

Going from memory here, try setting your Windows shortcut to:

wsl -e bash -lic "firefox"

That will run Bash:

  • As a login shell (-l) which will source your ~/.bash_profile
  • As an interactive shell (-i) which will source your ~/.bashrc
  • And run the command (-c) firefox
3
  • Markdown formatting exists for a reason: if steps are chronological, a number list should be used; bulleted lists are used when explaining details specific to the preceding step or paragraph. Grammatically, sentences shouldn't be split by code boxes since it discombobulates the content. For these reasons, I downvoted this answer and will remove it when the markdown formatting issues are resolved (it doesn't need to be like my edit, as edits are merely a suggestion for the author, however there are markdown issues to be resolved)
    – JW0914
    Commented May 31, 2022 at 13:28
  • 2
    @JW0914 Please keep in mind that markdown and HTML semantics have a purpose. You should never use single-bullets to indicate a call-out. Bullets are list items and should be used as such. Not doing so is confusing to screen reader software, at the very least. As such, I reverted your edits since they made the answer less readable. Also, numbered lists aren't needed for every flow. Answers are typically chronological in nature, and the paragraph flow is more readable unless short list items are needed. In that case, I would agree it is preferable to use a numbered list. Commented May 31, 2022 at 13:36
  • I have a different perspective due to the amount of complex, in-depth answers I've written (example 1, example 2, example 3, example 4, etc.). As previously stated, "...it doesn't need to be like my edit, as edits are merely a suggestion for the author,", however when lined up side-by-side, I disagree this answer in its current form is more readable.
    – JW0914
    Commented May 31, 2022 at 13:54
3

I recommend using the following syntax:

wsl -e bash -lic "nohup firefox &"

"&" in linux means "start in background". Without "&" we have active window with parent process (bash), with "&" but without "nohup" our process will end together with parent (bash windows).

With "nohup" and "&" all looks pretty - only Firefox process.

1

Further to:

Windows Shortcut (Target command)

This is what works best and most reliably for me in my particular circumstances i.e. Windows 10 with WSL2 Debian.

C:\Windows\System32\wsl.exe -d Debian -- bash -lic "nohup firefox &"

Note (if migrating from GWSL)

If you used to use GWSL for launching GUI apps before upgrading to WSL2, be sure to double check through your ~/.bashrc & ~/.profile (or ~/.bash_profile) files to remove any configs that were placed there by GWSL which might inadvertently overwrite the DISPLAY environment variable to something invalid containing your nameserver IP address (from /etc/resolve.conf).

In my case the legacy GWSL configs set DISPLAY to 1.1.1.1:0.0 instead of :0 which caused things to break.

1

While trying to get a Xilinx IDE to run in WSL with the required environment and my working directory I ended up with the following:

wsl.exe -e bash -lic ". /opt/Xilinx/14.7/ISE_DS/settings64.sh && cd /mnt/c/Users/%username%/Documents/ISE_Projects && nohup ise &"

Chaining commands using && allowed me to force the desired environment and working directory before launching the program.

The %username% substitution appears to be working.

You must log in to answer this question.