<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/r-in-the-windows-subsystem-for-linux/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/12/r-in-the-windows-subsystem-for-linux.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>R has been available for Windows since the very beginning, but if you have a Windows machine and want to use R within a Linux ecosystem, that's easy to do with the new Fall Creator's Update (version 1709). If you need access to the gcc toolchain for building R packages, or simply prefer the bash environment, it's easy to get things up and running.</p>
<p>Once you have things set up, you can launch a bash shell and run R at the terminal like you would in any Linux system. And that's because this <em>is</em> a Linux system: the <a rel="nofollow" href="https://docs.microsoft.com/en-us/windows/wsl/about" target="_blank">Windows Subsystem for Linux</a> is a complete Linux distribution running within Windows. <a rel="nofollow" href="https://docs.microsoft.com/en-us/windows/wsl/install-win10" target="_blank">This page provides the details on installing Linux on Windows</a>, but here are the basic steps you need and how to get the latest version of R up and running within it.</p>
<p>First, <strong>Enable the Windows Subsystem for Linux</strong> option. Go to <strong>Control Panel</strong> > <strong>Programs</strong> > <strong>Turn Windows Features on or off</strong> (or just type &quot;Windows Features&quot; into the search box), and select the &quot;Windows Subsystem for Linux&quot; option. You'll need to reboot, just this once. </p>
<p><a rel="nofollow" href="http://a2.typepad.com/6a0105360ba1c6970c01b8d2c717f2970c-pi" target="_blank"><img alt="Wsl2" title="Wsl2" src="http://a2.typepad.com/6a0105360ba1c6970c01b8d2c717f2970c-320wi"></a></p>
<p>Next, you'll need to install your preferred distribution of Linux from the Microsoft Store. If you search for &quot;Linux&quot; in the store, you'll find an entry &quot;Run Linux on Windows&quot; which will provide you with the available distributions. I'm using &quot;Ubuntu&quot;, which as of this writing is Ubuntu 16.04 (Xenial Xerus).</p>
<p><a rel="nofollow" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb09dfd4a3970d-pi" target="_blank"><img border="0" alt="Linuxdists" title="Linuxdists" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb09dfd4a3970d-800wi"></a></p>
<p>Once that's installed you can launch Ubuntu from the Start menu (just like any other app) to open a new bash shell window. The first time you launch, it will take a few minutes to install various components, and you'll also need to create a username and password. This is your Linux username, different from your Windows username. You'll automatically log in when you launch new Ubuntu sessions, but make sure you remember the password — you'll need it later.</p>
<p>From here you can go ahead and install R, but if you use the default Ubuntu repository you'll get an old version of R (R 3.2.3, from 2015). You probably want the latest version of R, so add <a rel="nofollow" href="https://cran.r-project.org/bin/linux/ubuntu/README.html" target="_blank">CRAN as a new package repository for Ubuntu</a>. You'll need to run these three commands as root, so enter the password you created above here if requested:</p>
<p><code>sudo echo &quot;deb http://cloud.r-project.org/bin/linux/ubuntu xenial/&quot; | sudo tee -a /etc/apt/sources.list</code></p>
<p><code>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9</code></p>
<p><code>sudo apt-get update</code></p>
<p>(Don't be surprised by the message <code>key E084DAB9: public key &quot;Michael Rutter &lt;marutter@gmail.com>&quot; imported</code>. That's how Ubuntu signs the R packages.)</p>
<p>Now you're all set to install the latest version of R, which can be done with:</p>
<pre><code>sudo apt-get install r-base</code></pre>
<p>And that's it! (Once all the dependencies install, anyway, which can take a while the first time.) Now you're all ready to run R from the Linux command line:</p>
<p><a rel="nofollow" href="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb09dfd53a970d-pi" target="_blank"><img border="0" alt="Rterminal" title="Rterminal" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb09dfd53a970d-800wi"></a></p>
<p>Note that you can access files on your Windows system from R — you'll find them at <code>/mnt/c/Users/</code></div>