Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for using R in WSL - run RStudio in WSL through a Linux graphical desktop #1

Closed
remlapmot opened this issue Apr 13, 2020 · 12 comments

Comments

@remlapmot
Copy link

I really enjoyed your blog about running R on Ubuntu on WSL.

I don't know if this is the best way to contact you - anyway - there is another method you could include.

You can install a graphical desktop environment in WSL and then run the Ubuntu version of RStudio in there.

I have followed online which show how to install MATE desktop and KFCE4 desktop on WSL (I can't make GNOME 3 work), e.g. here.

Below is some more possibly helpful info:

  • You need an X11 client for Windows e.g. Vcxsrv
  • Install MATE desktop in WSL with:
sudo apt update && apt upgrade -y
sudo apt install ubuntu-mate-desktop --no-install-recommends -y
sudo dpkg-reconfigure dbus && service dbus restart
sudo apt-get install mate-desktop-environment-extras
sudo apt install ubuntu-mate-icon-themes
  • With the X11 client running in Windows launch a graphical session within WSL with
mate-session
  • In WSL install R as you've done
  • Install RStudio by downloading the deb file from one of their install pages. I have been using the preview version from here.
  • Then install the .deb file with gdebi (changing the name of the .deb file as required)
sudo apt-get install gdebi-core
wget https://s3.amazonaws.com/rstudio-ide-build/desktop/bionic/amd64/rstudio-1.3.938-amd64.deb
sudo gdebi rstudio-1.3.938-amd64.deb
  • One quirk is that sometimes clicking the RStudio icon to launch it I just get a black window. When that happens I simply launch RStudio as sudo, e.g. sudo rstudio, and it works (having made sure rstudio is on my $PATH) (I guess not ideal running as sudo).
  • Here's a screenshot of my Windows 10 RStudio on the left and an X11 window running Ubuntu RStudio in WSL on the right.
    rstudio-win10-wsl

cheers
Tom

@jdblischak
Copy link
Owner

Hi @remlapmot! Thanks for reaching out. I'm definitely going to try this out. Depending on how it goes, I'll either update my previous post or create a new one.

This Ask Ubuntu thread may interest you. They also discuss using an X11 client to use RStudio Desktop running in the WSL, but they used various other X11 clients. Have you tried either MobaXTerm or X410?

@remlapmot
Copy link
Author

Great @jdblischak .

I haven't tried those other X11 clients but as far as I understand they basically have the same features. For example, VcXsrv can be run in windowed mode or (the whole Linux) desktop mode as well.

If you write a batch file to launch your WSL with a graphical desktop / windowed mode you change the relevant X11 executable/.xlaunch file. My batch file is here. It's a modified version from one of the tutorials.

Another method - Docker Desktop using WSL 2 engine

There is sort of another method of running R/RStudio which involves WSL 2. Docker Desktop on Windows can use a WSL 2 engine. In Docker Desktop settings tick Enable the experimental WSL 2 based engine.

docker-desktop-settings

You can launch any of the rocker, https://www.rocker-project.org/ containers.

As the rocker main page says you can launch base R with

docker run --rm -ti rocker/r-base

Or you can launch RStudio (I think server) with

docker run -e PASSWORD=yourpassword --rm -p 8787:8787 rocker/rstudio

You then access RStudio in your browser at http://localhost:8787 (username is rstudio, password yourpassword).

rstudio-docker

RAM issue with WSL 2

Another helpful point about WSL 2 is that it is useful to set the max amount of memory you want it to be able to use. Otherwise the Vmmem process ends up using almost all of your RAM. Hopefully this bug will be fixed in subsequent WSL 2 versions. The current fix is to specify memory and swap in a .wslconfig file. Mine is here.

@jdblischak
Copy link
Owner

@remlapmot Thanks again for all the advice and ideas. I recently returned to experimenting with my WSL1 setup, and I attempted to run RStudio in a graphical user interface. I successfully installed VcXsrv and was able to launch a graphical user interface.

Unfortunately the only thing I couldn't get working was running RStudio. With versions 2022.02.1-461, 1.3.938 (the version you used in your instructions), and 1.2.5042, I get the following error:

bash: /usr/bin/rstudio: cannot execute binary file: Exec format error

From Issue rstudio/rstudio#3615, the advice is to try RStudio 1.1. But this fails to install due to a missing dependency (I vaguely recall running into this error years ago when it was first released, but I don't have much motivation to resurrect RStudio 1.1).

Below is explicitly what I attempted. Are you currently able to run RStudio Desktop in WSL1? If yes, what version? Thanks!

# 2022.02.1-461 - Exec format error
wget https://s3.amazonaws.com/rstudio-ide-build/desktop/bionic/amd64/rstudio-2022.02.1-461-amd64.deb
sudo gdebi rstudio-2022.02.1-461-amd64.deb
rstudio
# bash: /usr/bin/rstudio: cannot execute binary file: Exec format error
sudo apt remove rstudio

# 1.3.938 - Exec format error
wget https://s3.amazonaws.com/rstudio-ide-build/desktop/bionic/amd64/rstudio-1.3.938-amd64.deb
sudo gdebi rstudio-1.3.938-amd64.deb
rstudio
# bash: /usr/bin/rstudio: cannot execute binary file: Exec format error
sudo apt remove rstudio

# 1.2.5042 - Exec format error
wget https://download1.rstudio.org/desktop/trusty/amd64/rstudio-1.2.5042-amd64.deb
sudo gdebi rstudio-1.2.5042-amd64.deb
rstudio
# bash: /usr/bin/rstudio: cannot execute binary file: Exec format error
sudo apt remove rstudio

# 1.1.463 - missing libgstreamer0.10-0
wget https://download1.rstudio.org/rstudio-1.1.463-amd64.deb
sudo gdebi rstudio-1.1.463-amd64.deb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading state information... Done
This package is uninstallable
Dependency is not satisfiable: libgstreamer0.10-0

@remlapmot
Copy link
Author

For your missing libgstreamer error I found this page here. Maybe one of the answers will help?

I have upgraded all my WSL instances to WSL version 2 - as WSL2 file system operations are noticeably faster than on WSL1.

There are a few more things you can try.

RStudio server - (I find most convenient)

I now use RStudio server running on my WSL 2 but I interact with it using a browser in Windows. I can't remember if this was one your previous methods. To use RStudio server

  • Download from say
wget https://s3.amazonaws.com/rstudio-ide-build/server/bionic/amd64/rstudio-server-2022.02.1-461-amd64.deb

Or go to Server Version section of one of their downloads pages, e.g. https://www.rstudio.com/products/rstudio/download/preview/

  • Try the installation with gdebi or dpkg. I think I remember that I needed at least 1 Linux system dependency to get this to install successfully - I think I just Googled the error message after the first time I ran the command below
sudo dpkg -i rstudio-server-2022.02.1-461-amd64.deb
  • Once installed, you need start to an RStudio server session with sudo powers (I think this is so it's accessible from a browser in Windows), so at WSL terminal run
sudo rstudio-server start
  • Then in your Windows browser go to http://localhost:8787 and you should find RStudio server running in that browser window - the beauty of WSL 2 (and probably WSL 1) is that you can access both your WSL and Windows files in this.

  • Once you've finished your work, you stop your rstudio-server sessions back in your WSL terminal with

sudo rstudio-server stop

Electron version of RStudio

For the development versions of RStudio they have Electron builds on their dailies website

https://dailies.rstudio.com/rstudio/spotted-wakerobin/electron/bionic/

https://dailies.rstudio.com/rstudio/spotted-wakerobin/electron/macos/

https://dailies.rstudio.com/rstudio/spotted-wakerobin/electron/windows/

You could try the bionic one.

Certainly on macOS the Electron version opens noticeably faster than the usual build.

Bundled graphical WSL apps

Instead of installing the X11 stuff yourself Microsoft's WSLg and the GWSL app in the Microsoft Store appear to have bundled it up more conveniently

@jdblischak
Copy link
Owner

@remlapmot Again, thanks for the very thorough answer!

Electron dailes

For the development versions of RStudio they have Electron builds on their dailies website

I liked this idea, so I tried this first. I didn't have much luck. I finally got it to launch by specifying --no-sandbox, but it was just a blank white window.

# WSL terminal
wget https://s3.amazonaws.com/rstudio-ide-build/electron/bionic/amd64/rstudio-2022.06.0-daily-270-amd64.deb
sudo gdebi rstudio-2022.06.0-daily-270-amd64.deb

# started xlaunch.exe
export DISPLAY=localhost:0
mate-session

# In MATE terminal
$ rstudio
[370:0406/094151.472708:FATAL:setuid_sandbox_host.cc(158)] The SUID sandbox helper binary was found, but is not configured correctly. Rather than run without sandboxing I'm aborting now. You need to make sure that /usr/lib/rstudio/chrome-sandbox is owned by root and has mode 4755.
Trace/breakpoint trap (core dumped)
[372:0100/000000.638758:ERROR:zygote_linux.cc(646)] write: Broken pipe (32)

$ ls -l /usr/lib/rstudio/chrome-sandbox
-rwxr-xr-x 1 root root 52536 Apr  5 00:47 /usr/lib/rstudio/chrome-sandbox

$ sudo rstudio
[0406/094307.885930:FATAL:electron_main_delegate.cc(292)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
Trace/breakpoint trap (core dumped)

$ rstudio --no-sandbox
# window opens, but it is blank white

$ sudo rstudio --no-sandbox
# window opens, but it is blank white

RStudio Server

I interact with it using a browser in Windows. I can't remember if this was one your previous methods

Yep, exactly. My current approach is to use RStudio Server. I use the OpenCPU infrastructure to install and run RStudio Server, but other than that the approaches have the same effect.

Microsoft Store

Instead of installing the X11 stuff yourself Microsoft's WSLg and the GWSL app in the Microsoft Store appear to have bundled it up more conveniently

I don't have access to the Microsoft Store on my work laptop. That is one of the main reasons I have been hesitant to migrate to WSL2. It was a colossal pain to get WSL1 installed (compared to how easy it was via the Microsoft Store on my personal laptop).

Missing libgstreamer

For your missing libgstreamer error I found this page here. Maybe one of the answers will help?

Yeah, this reminded me that I had old notes on how to fix this problem. I found my code for pinning old versions of libgstreamer with APT. This was from back in 2017. If I'm going to write a blog post advising people how to install RStudio Desktop in WSL, I don't want to use such outdated versions of libgstreamer and RStudio. If I can't get a more modern version working, it doesn't seem worth the trouble.

@remlapmot
Copy link
Author

In case helpful - you can upgrade WSL 1 instances to WSL 2 at the command line (but I don't know if this would need admin rights)

https://docs.microsoft.com/en-us/windows/wsl/install#upgrade-version-from-wsl-1-to-wsl-2

wsl --set-version <distro name> 2

@jdblischak
Copy link
Owner

In case helpful - you can upgrade WSL 1 instances to WSL 2 at the command line (but I don't know if this would need admin rights)

Ah, nice! I'm going to give this a try on my personal laptop first. I'm too afraid of borking my work laptop.

@remlapmot
Copy link
Author

I have run it twice - it ran quickly without error both times! (definitely felt a bit nervous pressing Enter!)

@jdblischak
Copy link
Owner

@remlapmot Thanks so much for taking the time to provide a detailed explanation of this useful option to install a graphical desktop in WSL, and for answering my questions. I finally got around to updating the blog post. I put a note right at the beginning that points to our discussion here

@remlapmot
Copy link
Author

thanks John - very nice of you; and very helpful additional links.

@jdblischak
Copy link
Owner

I finally took the time to upgrade my WSL from v1 to v2. As I had feared, it was non-trivial. My laptop wasn't configured properly to support WSL2. Below are my summarized notes (for my future self and anyone else interested).

PS C:\Users\john> wsl --status
Default Distribution: Ubuntu-18.04
Default Version: 2
WSL2 is not supported with your current machine configuration.
Please enable the "Virtual Machine Platform" optional component and ensure virtualization is enabled in the BIOS.
For information please visit https://aka.ms/enablevirtualization

The first step in the link in the error message is to check the Hyper-V system requirements. This led me down a confusing rabbit hole because Hyper-V is not available for the Home edition of Windows 10/11. Fortunately it's not required.

Next I followed these instructions to confirm that the BIOS setting "Intel Virtualization Technology" was already enabled.

Then I ran the following line in PowerShell to enable the "Virtual Machine Platform" and restarted my laptop (instructions)

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Only then was I able to migrate my existing WSL installation from v1 to v2

PS C:\WINDOWS\system32> wsl --set-version Ubuntu-18.04 2
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion in progress, this may take a few minutes.
The operation completed successfully.

So far everything is working well. I was also able to install a newer version of Ubuntu that also uses WSL v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants