Skip to content

Instantly share code, notes, and snippets.

@kalaschnik
Last active March 14, 2024 20:41
Show Gist options
  • Save kalaschnik/177a30bd02c9438fee1a93686fe60735 to your computer and use it in GitHub Desktop.
Save kalaschnik/177a30bd02c9438fee1a93686fe60735 to your computer and use it in GitHub Desktop.
Run RStudio in the Windows Subsystem for Linux 2 (WSL 2) using Pengwin and X410

Use RStudio within Windows Subsystem for Linux 2 (WSL 2)


Update June 2020

Microsoft will release GUI app support for WSL in the next Windows 11; more information are here:

In other words, there is no need to go through the pain of this manual anymore.


💡 Does WSL 1 work?

No, you will get cannot execute binary file: Exec format error when you try to run rstudio command.


Requirements / Limitations

Requirment

  • Windows 10 Pro 18917 or higher (which allows WSL 2)
  • X410
  • Pengwin

Limitations

  • I only tested this with X410. Other x systems might work as well. gHowever; compared to other X systems, it works very well with Hi-DPI systems, and it offers different displaying modes.
  • As of now I only managed to get the GUI of RStudio running in Pengwin. A Linux distro tailor-made for WSL. I tried it for Ubuntu 18.04 — But I get stuck on the Error WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed
Detailed Error
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-steven'
WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.
Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::DefaultSwapBehavior, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace,
profile  QSurfaceFormat::NoProfile)
Received signal 6
#0 0x7f448e42fa4f <unknown>
#1 0x7f448e42fe4b <unknown>
#2 0x7f448e4304ce <unknown>
#3 0x7f4489698890 <unknown>
#4 0x7f4487a0de97 gsignal
#5 0x7f4487a0f801 abort
#6 0x7f448992adcc QMessageLogger::fatal()
#7 0x7f44870e9afc QQuickWidgetPrivate::handleContextCreationFailure()
#8 0x7f44870e9cfa QQuickWidgetPrivate::createContext()
#9 0x7f44870ebe86 QQuickWidget::resizeEvent()
#10 0x7f4493b1998d QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget::resizeEvent()
#11 0x7f448aa8eea2 QWidget::event()
#12 0x7f44870ecacb QQuickWidget::event()
#13 0x7f4493b19c88 QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget::event()
#14 0x7f448aa50b3c QApplicationPrivate::notify_helper()
#15 0x7f448aa57d30 QApplication::notify()
#16 0x7f4489b17e28 QCoreApplication::notifyInternal2()
#17 0x7f448aa8763d QWidgetPrivate::sendPendingMoveAndResizeEvents()
#18 0x7f448aa8b1b3 QWidgetPrivate::show_helper()
#19 0x7f448aa8e375 QWidget::setVisible()
#20 0x7f448c962fb6 QtWebEngineCore::WebContentsAdapter::initialize()
#21 0x7f448c96521e QtWebEngineCore::WebContentsAdapter::load()
#22 0x7f448c965b50 QtWebEngineCore::WebContentsAdapter::load()
#23 0x56166919f0ac rstudio::desktop::SessionLauncher::launchFirstSession()
#24 0x5616691a055b rstudio::desktop::SessionLauncher::onLaunchFirstSession()
#25 0x7f4489b44801 QObject::event()
#26 0x7f448aa50b3c QApplicationPrivate::notify_helper()
#27 0x7f448aa57d30 QApplication::notify()
#28 0x7f4489b17e28 QCoreApplication::notifyInternal2()
#29 0x7f4489b1a857 QCoreApplicationPrivate::sendPostedEvents()
#30 0x7f4489b6fbb3 postEventSourceDispatch()
#31 0x7f4480e92417 g_main_context_dispatch
#32 0x7f4480e92650 <unknown>
#33 0x7f4480e926dc g_main_context_iteration
#34 0x7f4489b6f1ef QEventDispatcherGlib::processEvents()
#35 0x7f4489b1678a QEventLoop::exec()
#36 0x7f4489b1f190 QCoreApplication::exec()
#37 0x56166915ea0f main
#38 0x7f44879f0b97 __libc_start_main
#39 0x561669161d8a _start
r8: 0000000000000000  r9: 00007ffffe1b0d80 r10: 0000000000000008 r11: 0000000000000246
r12: 00007ffffe1b10b0 r13: 000056166b2a1720 r14: 000056166b2a1720 r15: 00007ffffe1b1620
di: 0000000000000002  si: 00007ffffe1b0d80  bp: 000056166b2a1720  bx: 00007f4489c3ae80
dx: 0000000000000000  ax: 0000000000000000  cx: 00007f4487a0de97  sp: 00007ffffe1b0d80
ip: 00007f4487a0de97 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.
Ubuntu Progress/Notes

Help wanted! Note, whatever Pengwin’s GUILIB is installing and setting up, this is doing the trick.

Ubuntu needs the following GUI packages

  1. sudo apt install libnss3
  2. sudo apt install libasound2
  3. sudo apt install libegl1-mesa

GUILIB from Pengwin sudo apt-get install -y -q xclip gnome-themes-standard gtk2-engines-murrine dbus dbus-x11 mesa-utils libqt5core5a binutils

Fix DBUS error:

  1. sudo -i
  2. sudo dbus-uuidgen > /var/lib/dbus/machine-id
  3. exit

WSL 2 and Pengwin Setup

  1. Setup WSL 2 (follow these steps)
  2. Open CMD:
    1. If you have already a distro installed you can see an list and version using wsl -l -v
    2. If you have already a WSL 1 distro installed, you can convert it to WSL 2: wsl --set-version <DistroName> 2. This will take some time.
    3. (You might get prompted to install WSL 2 Linux kernel update. Follow the link and install the msi. Redo step 2)
    4. Make WSL 2 your default: wsl --set-default-version 2
  3. Install Pengwin from Store and launch Terminal
  4. Restart Terminal, you get prompted to do so
  5. After you installed Pengwin, launch it to setup your username/password
  6. Launch pengwin-setup. Select GUI, then GUILIB from the the Menu. And wait for installation to finish
  7. Reopen terminal, and reopen again if prompted (this will apply guilib changes)

Your Distro is now using WSL 2. FYI: You can access the file system by typing \\wsl$ in your windows explorer’s address bar

Install R and RStudio

  1. Open your WSL2-enabled Distro
  2. sudo apt update (optional)
  3. sudo apt -y upgrade (optional)

Install R

  1. sudo apt -y install r-base
  2. Verify by typing R in your terminal.
  3. R will run an interactive session. Quite with q()

Download/Install RStudio

  1. wget https://download1.rstudio.org/desktop/bionic/amd64/rstudio-1.2.5033-amd64.deb
  2. sudo apt -f install (required to install .deb files)
  3. sudo dpkg -i rstudio-1.2.5033-amd64.deb
  4. If you get an error, try running step 2 again, and then step 3. I don’t know why, but that worked for me, after step 3 initially raised an error.

Install other GUI dependencies (Pengwin)
1. sudo apt install libnss3
2. sudo apt install libegl1-mesa

Restart terminal (twice, if prompted)

This was fixed WhitewaterFoundry/Pengwin#596

Install X410

  1. Install X410 from the store, then launch it.
  2. Right click X410 in system tray an click:
    1. Allow Public Access
    2. Windowed Apps (optional)
    3. DPI Scaling → High Quality (optional)

Launch RStudio

Open Pengin terminal and enter rstudio

@kalaschnik
Copy link
Author

Hello, I wanted the information if there was any progress with the ubuntu bug?

Hey GuilhermeFCO, sorry; I haven’t had the time to investigate for Ubuntu — I also updated this document at the very top that it will become obsolete due to Microsoft’s native graphical support in Windows 11 (or even now within the Dev Preview builds).

@Pablo-Leon
Copy link

Hi , have tou tried RStudio on WSLg on Win11.

I just did, and ran into some issues.
The main window of RStudios shows up on the Win11 desktop, with all it's menus, all functional.
But none of the inner panes are displayed.

Saw one error message stating that the sessión could not connect to R, but did not
found what action triggers the message.

Regards

@aborruso
Copy link

hi @kalaschnik first of all, thank you.

I have tried to do it, but I have [1] 1828 illegal hardware instruction rstudio. How could I solve it?

@kalaschnik
Copy link
Author

This was a workaround at the time for Windows 10 and WSL 1. It should work out of the box in Windows 11 WSL 2 with GUI App support.

@aborruso
Copy link

This was a workaround at the time for Windows 10 and WSL 1. It should work out of the box in Windows 11 WSL 2 with GUI App support.

Thank you again, it works

@CGMossa
Copy link

CGMossa commented Aug 17, 2023

I've tried the ubuntu route. Unfortunately, I'm stuck here:

kevin@DESKTOP-161ED27:~$ rstudio
Trace/breakpoint trap

@Agrover112
Copy link

RStudio downloda link is changed: https://posit.co/download/rstudio-server/

@abalter
Copy link

abalter commented Dec 19, 2023

That's for rstudio server, not rstudio desktop.

@abalter
Copy link

abalter commented Dec 19, 2023

@sujee119
Copy link

Hello kalaschnik,

I have installed the r base in a conda environment and tried to run r studio in the environment.

$ rstudio
"Uncaught TypeError: Cannot read property 'notifyRCrashed' of undefined"

i got the following error and the window looked like this.

image

Please kindly let me know a solution, Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment