How to Install R and RStudio on a Chromebook (April 2022 edition)

Chromebooks are great computers for students. You get a lot of value for money with a Chromebook. (I am typing this on an incredibly premium feeling 2nd generation Samsung Galaxy Chromebook that was recently on sale for $350 in the US. It has a new i3 chip, 8GB RAM, 128GB SSD, a good screen with touch and USI pen compatibility, it’s light with a flip design, good keys with backlighting and am awesome looking red chassis. Try getting all this in a Windows machine for $350. It is now my daily driver.) But are Chromebooks good for quant-minded people like myself? TL;DL they are! Read to get the details.

Recently someone (a seasoned instructor of R) asked me if I have tips for his student on installing R and RStudio for a Chromebooks. Chromebooks have been my preferred platform for years. The Pandemic unfortunately drove me back to the classic platforms for specialized tasks that are related to the new realities of teaching but I still prefer a Chromebook as my daily driver. I also use R and RStudio regularly. I love the Chromebook simplicity but I also like the flexibility that an on demand Debian Linux installation offers. (Yes, Chromebooks have the ability of running an entire Linux install in the background with all the facilities Linux has to offer.) Of course, I have over 20 years of Linux experience. Not everyone does. And to install R and RStudio, you will have to use Linux and it can be super intimidating at first. So here’s a step by step guide to help you set up and run Linux on your Chromebook, and install R and RStudio. Once these steps are completed, the use of RStudio on a Chromebook is as easy as using any other app on your Chromebook (mostly). I will try to help you both by giving you the steps you need to do and explain what is going on in these steps to help demystify the process. So let’s get started.

(One caveat. This was written for Intel/AMD based Chromebooks. Since, I have tried to do all this on an ARM based Chromebook and concluded that maybe it can be done, but just don’t. Really! Don’t! R’s packaged version installs no problem. The installation of the up to date version is painful, but doable. R-Studio is a nightmare I lived for several days with agonizing breaks in between. And I barely made a dent. I think with enough persistence I could make it work, but it is not worth it, the instructions would be terrifying and would inevitably break with every new version of every dependency and etc. Stick to Intel if you want RStudio and in a pinch, the old version of R works like a charm on ARM.)

Step 1: Tell your Chromebook which Linux version you want to use

At the time of writing I am on ChromeOS Version 100 (Stable Channel). This version of ChromeOS, by default, runs Debian 10 which is nicknamed Buster. But it can run version 11 (Bullseye) as well and you will have better results with the newer version. Before we do anything else, let’s tell the Chromebook that we want Bullseye. My suspicion is that Bullseye will become the default soon. In the future you may not need to do this step at all.

(Note: if you have activated your Linux system on the Chromebook, this won’t work. And upgrading is a nightmare at this point. I’d recommend starting over with Linux by deleting your Linux system. Of course, if you’ve been using that system for multiple things, that’s not a good idea. But then again, if you have been using your Linux, you probably have enough experience to figure out how to install R and RStudio.)

Open Chrome (or a new Chrome tab). Type:

chrome://flags

You should get a list of (mostly still experimental) features you can tweak or turn on and off on your Chromebook. Look for “Debian version for new Crostini containers”. Best if you start typing Debian in the search bar instead of scrolling. Once you found it, set this option to Bullseye (change it from Default).

You may need to restart once this is done.

Step 2: Set up the Linux container.

Once this is done, you need to set up a Linux container on your Chromebook. Open Settings and hit:

Advanced -> Developers -> Linux development environment -> Turn on.

This may take a while. You also may have to set how much space you allow for Linux. Best to use the default and this can be changed later but I’d say 5GB should be more than enough. (Use 2GB if you are strapped for space.) Once this is done, you should have an icon looking something like this in your menu.

This icon will open a Linux Terminal, allowing you to work inside Linux. (Not sure if it is automatically pinned into the shelf on the  bottom. If not, consider pinning it.) We’ll need to hit this next.

Step 3: Open Linux, and do the mandatory regular maintenance. 

When you open this, you will get a black box with a blinking cursor that you can give commands to. People experience with Linux are probably quite used to working in this so-called Terminal. But if you are not, this can be intimidating. Don’t worry. We don’t have to use this often.

You want to basically update your Linux. Make sure everything is up to date. You do this by typing:

sudo apt-get update && sudo apt-get upgrade -y

(If you care, sudo do the following as a superuser who can do anything, normal users can’t install things – sometimes you may have to type your password when you give this command) apt-get is what manages everything installed in Debian Linux and update means check what packages are on the server.  && means I am giving another command now, which is the same command with upgrade meaning upgrade all packages that are installed and newer versions are available on the server. -y is not that important. It basically says, don’t ask questions during this process, rather say yes [or whatever the default response is] to everything.

Step 4: Install R

Bullseye has R 4.0.4 built in. [This is what works well on ARM as well.] Buster has an even older version. 3.x.x I suspect. For an intro to stats class it may be enough. (To install this outdated version, type: sudo apt-get install r-base r-base-dev libnss3 and move to the next step. And to explain what this command does, you are already familiar with sudo and apt-get, install installs stuff and r-base is the name of R in Debian and r-base-dev is an extension that allows you to install packages, finally libnss3 is needed for RStudio but I couldn’t figure out why). But you probably want the most up to date version of R running on your computer [which at the most recent update of this post is 4.2], not whatever was originally included in this version of Debian. So we need to jump a few more hoops to make sure it is not the default version of R that is installed, but the new version.

Remember that we talked about updating what packages are available on a server? We can add a new server here pointing to the most up to date version of R. R actually maintains a server with which you can keep R in Debian up to date. To make Debian use this server you need to do two things. Add it to the list of servers Debian checks when you run apt-get update, and authenticate the server ensuring nobody can hijack it and install malicious stuff from there. (Linux is pretty secure from this perspective.) To do these we need to install a few other things we will use in the process.

(Note: when you install stuff, sometimes there are so called dependencies that also need to be installed before the stuff you specified can be installed. So don’t worry about it if Debian is telling you more stuff will be installed than what you asked for. This is normal.)

sudo apt-get install dirmngr gnupg apt-utils apt-transport-https ca-certificates software-properties-common

With these installed, now we can authenticate the server we are about to add (that big ugly string is the key for the authentication – just go with it).

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key '95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7'

Then we add the R server to the list of servers Debian should update from

sudo add-apt-repository 'deb http://cloud.r-project.org/bin/linux/debian bullseye-cran40/'

Then we update the list of what’s available on the servers. (We’ve done this before. But now it will include the new server we just added.)

sudo apt-get update && sudo apt-get upgrade -y

And we install R the same way we would have installed the default (older) version. If you did that before, the previous step will update the already installed version of R to the newer version. So no worries there, you can skip this. Or don’t. It will just tell you that r-base and r-base-dev are already installed.

sudo apt-get install r-base r-base-dev

Finally you need to install libnss3. (Don’t ask why or why it doesn’t install it as a dependency. Definitely don’t ask what it is. No clue. But I had trouble with RStudio without installing it. Maybe R would have issues too. I didn’t check. But multiple sources suggested this needs to be installed in addition to r-base and r-base-dev.)

sudo apt-get install libnss3

Step 5: So R is installed. Now you need RStudio.

RStudio must be manually downloaded from the RStudio website and installed also manually. So go to the RStudio website and download the free RStudio Desktop for Debian 11. (Same version for Ubuntu. You may see it listed as Ubuntu/Debian.) Link at the time of writing is here: https://www.rstudio.com/products/rstudio/download/#download

What you downloaded is a file ending with .deb (this stands for Debian package). Put this in the home directory of your Linux file system in the files app.

When you want to install such a deb file, and not something on a Debian server, you have to tell apt-get where the file is. The ./ in front of the file name means in the folder I am working in (as opposed to the server where it won’t find it). Make sure the file name matches what you downloaded. This is the up to date version at the time of writing, but RStudio updates regularly so chances are you will be grabbing a newer version with a newer date and version number.

sudo apt-get install ./rstudio-2022.02.1-461-amd64.deb

Et voilà. RStudio is installed. It should be in the list of Chromebook icons called Linux apps. Run it from there. If you are going to use RStudio regularly, I would pin it to the shelf on the bottom. And again, you will not have to (often) do anything in the Linux terminal. There are minor exceptions I will list below. Once you verified RStudio works, you may also want to delete the deb package you installed it from before you close the terminal. Keeping that is a waste of space. 

sudo rm rstudio-2022.02.1-461-amd64.deb

Additional Info

As a general good practice, I always make a folder in my Linux partition I call “data”. For all R projects I make sub-folders in this “data” folder. In the R code, if you want to refer to a folder in R with the setwd command you do it by

 setwd(“~/data/project1”) 

assuming the sub-folder for your first project is “project1”. ~ means in my (Linux) home directory and the rest is pretty self explanatory (I hope). This is going to be an important folder. Remember to back it up regularly. I occasionally dragged this over to my Google Drive to make a copy. (Though, now I am working on setting up something more automatic that syncs this folder across all my devices and the cloud. UPDATE: mega.nz ended up working great for this. I had less luck with pCloud. I should be recommending GitHub here, but if you just want a quick and dirty solution, Mega works.)

Now I said above that you will not have to do much in the Linux Terminal. There are three exceptions. Once in a while it is a good idea to update your Debian packages. Open the terminal and:

sudo apt-get update && sudo apt-get upgrade -y

That’s it. This will update to the newest version of 4.x.x R and update all other packages installed to the newest supplied by Debian Bullseye. (Once R moves to 5.0, the list of servers will need to be updated and R, along with all of its packages, reinstalled. But that’s gonna be a while.)

Sometimes you may want to update your version of RStudio. Repeat Step 5 once a newer version of RStudio is available. You can check the current version of your RStudio under Help -> About RStudio. Version mirrors the file name.

Finally, when installing packages in R / RStudio, sometimes R will tell you that it cannot install something because it requires tools not available. See example below. 

See how it said “Configuration failed because libcurl was not found.” That is your cue that something needs to be installed still. But (despite the intimidating mess around it) R is really clearly telling you what you need to do. On Debian or Ubuntu you need to install the libcurl4-openssl-dev package. (These are always packages available within Debian.) And, if you paid attention above, you know how to do this already. For the example in the picture, open the terminal and:

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install libcurl4-openssl-dev

And that’s it. You just need to not panic and find what went wrong with the given R-package installation. It is almost inevitably a missing package that you need to install and it tells you what it is. If this was not the issue, find whatever clue R gives you and Google is your friend. If that doesn’t help, turn to the forums online. They will help.

Conclusions

In sum, Chromebooks are just fine to run R. And Linux is generally a good platform for most quant work. Chromebooks give you a full Linux install which is an extremely flexible tool for data science. Many people opt to use just Linux for their data science needs. With a Chromebook, all that power is available at your fingertips on demand while you have a pretty simple to use computer where the tech and the platform does not get in the way of your day to day computing tasks.

I honestly don’t use the Linux for much,  but I could. They are working on it but Audio is still an issue with Linux on Chromebooks but soon I expect I’ll be using Audacity for audio editing and maybe even a video editor. GIMP is a good Photoshop replacement that you might prefer over web apps. What I do have installed in addition to R is LibreOffice which is helpful. I usually use Google Docs but sometimes having a second platform helps. I also have GNU PSPP (an SPSS clone) installed though I barely ever open it. I keep an extra browser and text editor, I have an FTP client (FileZilla) and Signal for desktop installed.  These are some additional tools you can use with Linux.

Sources

https://beebom.com/how-update-debian-bullseye-chromebook/ 

https://www.how2shout.com/linux/install-the-latest-r-programming-language-version-on-debian-11-bullseye/ 

https://www.linuxmadesimple.info/2021/03/how-to-install-rstudio-on-chromebook.html 

https://community.rstudio.com/t/error-in-install-packages-ubuntu-20-04-lts/67443 

https://community.rstudio.com/t/installation-error-cannot-find-libsmime3-so/30646 

And thanks to Jeff Lessem for the tip on how to make this even more simple.