Skip to content

Instantly share code, notes, and snippets.

@pinusm
Forked from kalaschnik/RStudio-in-WSL2.md
Created November 23, 2020 17:15
Show Gist options
  • Save pinusm/e58a1440c7f6a5676e1ad4a26720873a to your computer and use it in GitHub Desktop.
Save pinusm/e58a1440c7f6a5676e1ad4a26720873a 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)


💡 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

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