如何在Linux Mint 18.3中将R从3.4.4版本升级到3.5版本?
Hey there! Let's walk through upgrading your R from 3.4.4 to 3.5 on Linux Mint 18.3. Since Mint 18.3 is built on Ubuntu Xenial (16.04), we'll use steps tailored to that base system.
First, it's smart to save a list of your current R packages so you can restore them after the upgrade. Open up R and run this:
installed_packages <- installed.packages()[,"Package"] save(installed_packages, file = "~/R_installed_packages.RData")
This will save a file in your home directory with all your package names—we'll use this later.
The default repositories on Mint 18.3 might not have R 3.5, so we need to add the official CRAN repo for Xenial.
First, create a new sources list file for CRAN:
sudo nano /etc/apt/sources.list.d/cran.list
Paste this line into the file:
deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/
Save and exit by pressing Ctrl+O, hit Enter, then Ctrl+X.
Next, add the CRAN GPG key to avoid signature errors when updating packages:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
Now let's refresh the package index and install the latest R 3.5 version:
sudo apt update
Once that finishes, run:
sudo apt install r-base r-base-dev
This will replace your existing R 3.4.4 installation with R 3.5. To confirm it worked, run:
R --version
You should see output showing R 3.5.x (like 3.5.3, which is the latest patch for 3.5).
R 3.5 might have compatibility changes with older packages, so you'll need to reinstall them. Open R again and run:
load("~/R_installed_packages.RData") install.packages(installed_packages)
If any packages fail to install, check the error message—you might need to install system-level dependencies first. For example, common ones like libcurl4-openssl-dev, libxml2-dev, or libssl-dev can be installed with sudo apt install [package-name].
- If you get a "signature invalid" error during
apt update, double-check that you added the correct GPG key. - If
apt updatefails to connect to the CRAN repo, try switching to a different CRAN mirror (replace the URL incran.listwith another valid mirror address). - If a package won't install, check its CRAN page to see if it supports R 3.5—some older packages might need to be installed from source or replaced with alternatives.
内容的提问来源于stack exchange,提问作者Farzad

