How to upgrade R version on WSL? - r

I'm running Ubuntu in Windows Subsystem for Linux, and apt-get update isn't finding the newest versions of r-base. On Ubuntu 16.04, the newest R version it gets is 3.2.3. How do I upgrade to newer versions of R?

It turns out that the version of r-base in the default Ubuntu repository is behind the newest version of r-base from CRAN.
The solution is to add R-CRAN to /etc/apt/sources.list, using the instructions here: https://cran.r-project.org/bin/linux/ubuntu/
sudo sh -c 'echo "deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/" >> /etc/apt/sources.list'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo apt-get update
sudo apt-get install --only-upgrade r-base # This upgrades r-base if it's already installed; otherwise it doesn't install it

As #DirkEddelbuettel said in his comments, this README has helpful information for how you can update your R version in a Windows subsystem for Linux (WSL) setting. For me, I updated from R 3.4 to R 4.0 on Ubuntu 18.04.
I am running bionic (I used lsb_release -a to find out), and I wanted R 4.0 so I picked the appropriate deb line (for me: deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/) to add to my /etc/apt/sources.list file (had to use sudo vim /etc/apt/sources.list to add this line to the end). Then I ran sudo apt-get update and sudo apt-get install r-base. Now I have 4.0.2, the newest version. Just pick the particular Ubuntu/R combo that you want based on the options from the README. I hope this can help someone.

Related

R-base could not be upgraded to 4.0: showing "r-base is already the newest version (3.4.4-1xenial0)"

I have tried to upgrade R from 3.4.4 to 4.0 in Ubuntu 16.04.7 LTS (Xenial Xerus). I have followed and run the following scripts.
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
$ sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/'
$ sudo apt-get update
$ sudo apt install r-base
Output:
"Reading package lists... Done
Building dependency tree
Reading state information... Done
r-base is already the newest version (3.4.4-1xenial0)".
The terminal always showed that "r-base is already the newest version" and refused to upgrade. I tried to upgrade R 3.6 as well and got a similar issue. Any thoughts? Thank you so much for your help.

Upgrading r-base from v3.6 to v4.0 Linux

I am trying to install R-base 4.0, but it keeps installing v3.6. I've tried:
sudo apt install deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/
sudo apt-get install r-base
and v3.6, not 4.0 was installed. Next I tried:
sudo apt install deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/
sudo apt-get upgrade r-base
and it didn't work.
How do I upgrade to Rv4.0? I am using Pop_Os, no Ubuntu. Could that be the issue?
First off, your initial line is wrong. There is not such apt install deb command. You are supposed to edit the apt sources file by hand (though these days there may be GUI solutions to it as well).
Second, you omitted to actually use the new repo by not running sudo apt update (or equally sudo apt-get update). You must update the local indices.
Third, a preferred way is to just upgrade as you (almost) did in the second paragraph. But upgrade takes no package argument!
Fourth, this has nothing to do with Pop!OS as we are talking only about apt and apt-get here.
For completeness, I did a little blog and video about the R 3.6.* to R 4.0.* upgrade. More info here if you care.
PS Fifth, as r2evans noted in the comment, be sure to pick the right distro. I run straight Ubuntu so "focal" it is more me. You probably want R 4.0.* from the Ubuntu build matching your Pop!OS build.

How to upgrade IRKernel in Ubuntu?

On Ubuntu 18.04 LTS, while working R in JupyterNotebook (without Anaconda), the IRKernel is reading the R version 3.4. For using some packages like cowplot it is necessary to have at least version 3.5.
Basically, two steps should be taken:
Update R. These and that answers were a guideline.
Update IRKernel. The offical IRKernel instructions for Linux were useful.
Next, is described the complete procedure
1. Add Key to server
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
2. Add Entry to sources.list
echo 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/' | sudo tee -a /etc/apt/sources.list
Depending on the linux you're using you should change, for example, bionic by xenial or cosmic, check out https://cran.r-project.org/bin/linux/ubuntu/README.html
3. Update Programs
According to the instructions in the above link, we should do the following:
sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev
4. Update /.local/share/jupyter/kernels/ir
type R in the console and follow the next steps according to this link
# In the console
R
# Inside R
install.packages(c('repr', 'IRdisplay', 'IRkernel'), type = 'source')
getRversion() # to verify the new R version
IRKernel::installspec()
This should show the following message:
[InstallKernelSpec] Removing existing kernelspec in /home/user_name/.local/share/jupyter/kernels/ir
[InstallKernelSpec] Installed kernelspec ir in /home/user_name/.local/share/jupyter/kernels/ir
As a final remark, you should remove the older version of R, which you can find in ~/R/x86_64-pc-linux-gnu-library, where you will now have two directories with two different versions or R (remove the older one).

Update R base - Ubuntu from 3.4.4 to 3.5.2 - Azure

I'm using Ubuntu 16.04 on Azure Linux Virtual Machine
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
The current R version for Rstudio/Rserver is 3.4.4 and I would like to update it to the latest version (i.e. version 3.5.2)
R --version
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
From some reasons, the most common method doesn't work:
apt-get update
apt-get upgrade
So I did some research and find this post on biostars.org
One of the posts says the following codes might work
sudo su
echo "deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
apt-get update
apt-get install r-base
apt-get install r-base-dev
However, after apt-get install r-base I'm getting the following error message:
root#VMforR:/usr/local/bin# apt-get install r-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
r-base : Depends: r-recommended (= 3.5.2-1xenial) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
I don't understand what "held broken packages" means, and more importantly, how to update the R base?
What worked for me was to add the PPA of Michael Rutter:
sudo add-apt-repository ppa:marutter/rrutter3.5
sudo apt-get update
Update R:
sudo apt install r-api-3.5
I'm with the 16.04 LTS ubuntu.
Have tried some other methods, the following seems to work:
sudo apt-get install r-base-core=3.5.2-1xenial
Ref:
1. Install particular version(2.15.2) of r-base on ubuntu
2. https://cran.rstudio.com/bin/linux/ubuntu/xenial-cran35/
But I'm not sure if this also work for others or not, as I can't reproduce it.
After
apt-get update
do
apt-get dist-upgrade
first to "move your installation forward". That includes upgrading already installed packages. It should just upgrade your R installation (unless you also switch / need to switch repositories).
The r-sig-debian list is good and patient with basic 'how do it od X for R on Debian/Ubuntu'. Consider subscribing to lurk and/or ask questions.
Mine said some of my packages were missing. So, I ran sudo dpkg --configure -a and then re-run the R --update and it worked to correct the missing package error.

What's the best way to install R packages on Linux?

I happen to have Linux Mint on my machine (and I am not very experienced in Linux). When trying to install R packages (using install.packages()) on Linux Mint, I've got the following problems:
The installation process goes very slowly (the packages are being compiled each time)
Some packages could not be installed due to compilation errors.
So, I wonder, is there any standard approach to install packages for Linux Mint?
The repositories are available in any standard Ubuntu installation via the package manager. To get the latest version try adding cran.rstudio.com repository for Ubuntu:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu xenial/'
sudo apt-get update
sudo apt-get install r-base
(Details see R-Project homepage)

Resources