4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSLでUbuntu 20.04 + RStudio Server + R4.0

Posted at

WindowsのRStudioで日本語のdataを扱おうとするとコンソールにちゃんと出力されなかったりするので、RStudio Serverを入れて解決。

必要なもの

  • Windows 10 Professional (May 2020 update 適用済み)の入ったパソコン

Windows Subsystem for Linux 2のインストール

WSL2が入っていないとUbuntu 20.04で動かない機能があるの、インストールしないといけない。これは、Windows 10 version 2004から可能。私の場合はすでにWSL1にUbuntu 20.04が入った環境で始めたので、アップデートが必要だった。

まず、cmdでWSLのバージョンを確認。

wsl -l -v

出力がこうなっていたらWLS1。

  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         1

WSL2を使えるようにする

"Virtual Machine Platform"を有効にしないといけないので、管理者として開いたPowerShellで、

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

この後マシンを再起動。

次に、WSL2をデフォルトにする。管理者権限で起動したPowerShellで、

wsl --set-default-version 2

UbuntuのWSLのバージョンを変える

再びPowerShellで

wsl --set-version Ubuntu-20.04 2

こんなメッセージが出たら成功

Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.

一応cmdで確認

C:\Users\****>wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         2

R4.0のインストール

Ubuntuのシェルを起動して

  1. 諸々アップデート

    sudo apt-get update
    sudo apt-get upgrade -y
    
  2. R4.0の使えるUbuntu 20.04のリポジトリを登録

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
    sudo add-apt-repository 'deb https://cran.r-project.org/bin/Linux/ubuntu focal-cran40/'
    

    この、リポジトリの登録が、WSL1だと動かないので、WSL2が必要になる。

  3. Rのインストール

sudo apt install -y r-base r-base-core r-recommended r-base-dev gdebi-core build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev

RStudio Serverのインストール

wget https://rstudio.org/download/latest/stable/server/bionic/rstudio-server-latest-amd64.deb
sudo gdebi rstudio-server-latest-amd64.deb

私の環境だとインストールしたら、サーバーが立ち上がっていたけど、一応起動コマンド

sudo rstudio-server start

ここまですれば、後はWindowsのブラウザからhttp://localhost:8787で接続できるはず。

4
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?