<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/installation-of-r-3-5-on-ubuntu-18-04-lts-and-tips-for-spatial-packages/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rtask.thinkr.fr/blog/installation-of-r-3-5-on-ubuntu-18-04-lts-and-tips-for-spatial-packages/"> (en) The R Task Force</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong>Do you plan to upgrade your server installation from Ubuntu 16.04 to Ubuntu 18.04 LTS ? It is also the best time to migrate to R 3.5 ! By the way, if you always found difficult to install R packages for geographical data on Ubuntu, this time is over. Just follow the guide…</strong></p>
<h2>New Ubuntu version and new R version</h2>
<p><img sizes="(max-width: 150px) 100vw, 150px" src="https://i0.wp.com/rtask.thinkr.fr/wp-content/uploads/ubuntu-r-150x150.png?resize=150%2C150&ssl=1" alt="ubuntu-r" width="150" class="wp-image-599" data-recalc-dims="1" height="150"></p>
<p>If you use Ubuntu on your laptop or on your servers in your company, chances are high that you use a Long Term Support (LTS) version. Using a <strong>LTS version is safer for companies</strong> having stability constraints. This avoids possible breaking changes that would compromise your workflows and thus your business. Indeed, if you work with spatial data in R on Ubuntu, you probably also noticed that installation using recent versions of packages like <a rel="nofollow" href="https://gdal.org/" target="_blank">gdal</a>, <a rel="nofollow" href="https://trac.osgeo.org/geos/" target="_blank">geos</a>, <a rel="nofollow" href="https://proj4.org/" target="_blank">proj</a> or <a rel="nofollow" href="https://www.unidata.ucar.edu/software/netcdf/" target="_blank">netcdf</a> was only possible if you are working on a LTS version of Ubuntu using <a rel="nofollow" href="https://launchpad.net/~ubuntugis" target="_blank">UbuntuGIS PPA</a>. This month, the first point release of <a rel="nofollow" href="https://www.ubuntu.com/download/server" target="_blank">Ubuntu 18.04.1 Bionic Beaver for server</a> or <a rel="nofollow" href="https://www.ubuntu.com/download/desktop" target="_blank">desktop</a> is available for download. If you are still using Ubuntu 16.04 you will now be proposed this upgrade.</p>
<p>During the last few months, you also heard about the <a rel="nofollow" href="https://stat.ethz.ch/pipermail/r-announce/2018/000628.html" target="_blank">release of R 3.5</a> as announced by the R Core team. This introduced lots of performance improvements thanks to the <a rel="nofollow" href="https://svn.r-project.org/R/branches/ALTREP/ALTREP.html" target="_blank">ALTREP</a>. Now that the first maintenance release R 3.5.1 is out, you may also want to put it in production at work.</p>
<p>While your are playing with a series of <code>sudo apt update</code> commands, why not do both upgrades at the same time ?</p>
<h2>Upgrade to Ubuntu 18.04</h2>
<p><img sizes="(max-width: 150px) 100vw, 150px" src="https://i1.wp.com/rtask.thinkr.fr/wp-content/uploads/ubuntu-logo-150x150.png?resize=150%2C150&ssl=1" alt="ubuntu-logo" width="150" class="wp-image-598" data-recalc-dims="1" height="150">As always, <strong>be sure to have some backups</strong> of your files before starting migration ! If you are running Ubuntu 16.04 LTS, you may see the new release using the “update core manager”. Be sure it is installed :</p>
<pre><code>sudo apt-get install update-manager-core</code></pre>
<p>then run</p>
<pre><code>sudo do-release-upgrade</code></pre>
<p>This should work if you allowed only LTS versions to be installed. In my own case, maybe I was not patient enough, but the new version was not proposed. Then you can temporarily allow for “normal” release, which, here, will propose you the last version available 18.04. The one we want. Be careful with this change. If you are using your computer at work in production mode, set it back to “lts” as soon as you have the LTS installed.</p>
<p>Check <code>/etc/update-manager/release-upgrades</code> and change the line:</p>
<pre><code>Prompt=lts</code></pre>
<p>to:</p>
<pre><code>Prompt=normal</code></pre>
<p>Then you can run <code>sudo do-release-upgrade</code></p>
<p>Follow instructions and you’re done for the Ubuntu upgrade.</p>
<h2>Delete previous version of R</h2>
<p><img sizes="(max-width: 150px) 100vw, 150px" src="https://i0.wp.com/rtask.thinkr.fr/wp-content/uploads/ubuntu-r-150x150.png?resize=150%2C150&ssl=1" alt="ubuntu-r" width="150" class="wp-image-599" data-recalc-dims="1" height="150"></p>
<h3>Remove additional repositories</h3>
<p>To be able to use R 3.5, you will have to <strong>delete everything about the previous R</strong> version.</p>
<p>We first need to check if you used one of the R mirror server. Maybe you do, maybe you don’t… The R mirror server will be one of these: <a rel="nofollow" href="https://cran.r-project.org/mirrors.html" target="_blank">https://cran.r-project.org/mirrors.html</a>. The name of this server can be listed in the file “/etc/apt/sources.list” that you can edit with:</p>
<p><em>In the terminal:</em></p>
<pre><code>sudo vi /etc/apt/sources.list</code></pre>
<p>Find the line(s) that looks like <code>deb https://mirror.ibcp.fr/pub/CRAN/ xenial/</code> and comment it with a <code>#</code>.</p>
<p>If you did not find these lines, the server may be listed in an external file listed in “/etc/apt/sources.list.d”. Find the “name.of.file.with.a.mirror.name” (replace this path with the appropriate one) and delete the files.</p>
<p><em>In the terminal:</em></p>
<pre><code>ls /etc/apt/sources.list.d
sudo rm -i /etc/apt/sources.list.d/name.of.file.for.mirror.list</code></pre>
<p>If you did not find it, you probably installed R using the Ubuntu default servers. Then, you do not have anything else to do.</p>
<h3>Remove Ubuntu packages for R</h3>
<p>Now you need to <strong>remove all Ubuntu packages for R</strong> and clean your installation.</p>
<p><em>In the terminal:</em></p>
<pre><code>sudo apt purge r-base r-recommended r-cran-*
sudo apt autoremove
sudo apt update</code></pre>
<p>R should be totally removed after that.</p>
<h2>Install new version of R (3.5)</h2>
<p><img sizes="(max-width: 150px) 100vw, 150px" src="https://i0.wp.com/rtask.thinkr.fr/wp-content/uploads/ubuntu-r-150x150.png?resize=150%2C150&ssl=1" alt="ubuntu-r" width="150" class="wp-image-599" data-recalc-dims="1" height="150"></p>
<h3>Set new Ubuntu repositories for R 3.5</h3>
<p>Detailed installation instructions are on <a rel="nofollow" href="https://cran.r-project.org/bin/linux/ubuntu/" target="_blank">https://cran.r-project.org/bin/linux/ubuntu/</a>. Thanks to <a rel="nofollow" href="http://dirk.eddelbuettel.com/blog/" target="_blank">Dirk Eddelbuettel</a> and <a rel="nofollow" href="http://rubuntu.netlify.com/" target="_blank">Michael Rutter</a>, installing R on Ubuntu is a child’s play !<br>
We will use the new mirror <a rel="nofollow" href="https://cloud.r-project.org/" target="_blank">https://cloud.r-project.org</a>, which will be automatically redirected to a nearby CRAN mirror.</p>
<p><em>In the terminal:</em></p>
<pre><code>sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo apt update</code></pre>
<h3>Install R 3.5</h3>
<p>Very few deb packages are necessary:</p>
<p><em>In the terminal:</em></p>
<pre><code>sudo apt install r-base r-base-core r-recommended</code></pre>
<h3>Install other packages binaries with Ubuntu</h3>
<p>On a personal level, I have some R packages installed with an Ubuntu PPA (Personal Package Archives) because I trust maintainers and I am sure this R packages will work with my Ubuntu distribution. They require Linux dependencies that can be complicated to install. This is the case for mapping packages or those with java in them.<br>
With R 3.5, Ubuntu packages required to be rebuilt differently than with previous version. <a rel="nofollow" href="http://rubuntu.netlify.com/post/2018-06-11-r-3.5-on-debian-and-ubuntu-update/" target="_blank">Michael Rutter explains this on his dedicated blog</a>. Hence, you’ll need to use his PPA before installing Ubuntu packages for R (starting with “r-cran-”).</p>
<p><em>In the terminal (my personal selection):</em></p>
<pre><code>sudo add-apt-repository ppa:marutter/c2d4u3.5
sudo apt-get update
sudo apt install r-cran-rgl r-cran-rjags r-cran-snow r-cran-ggplot2 r-cran-igraph r-cran-lme4 r-cran-rjava r-cran-devtools r-cran-roxygen2 r-cran-rjava r-cran-xlsx</code></pre>
<h3>Install packages for spatial data analyses in Ubuntu</h3>
<p><img sizes="(max-width: 150px) 100vw, 150px" src="https://i2.wp.com/rtask.thinkr.fr/wp-content/uploads/ubuntu-carto-r-150x150.png?resize=150%2C150&ssl=1" alt="ubuntu-carto-r" width="150" class="wp-image-602" data-recalc-dims="1" height="150">Installation of R packages like {sf}, {sp}, {rgdal}, {rgeos}, … may require some external Ubuntu packages. This has been made easy with the <a rel="nofollow" href="https://launchpad.net/~ubuntugis" target="_blank">UbuntuGIS PPA</a>. The maintainers team is small and it may takes some time before packages are released for your distribution. Only Ubuntu LTS distributions are available. Also, as of today, packages for Ubuntu 18.04 are not available: if you have the skills, you may <a rel="nofollow" href="https://launchpad.net/~ubuntugis" target="_blank">help them!</a>.</p>
<blockquote>
<p>With Ubuntu 16.04, UbuntuGIS is necessary for the installation of the spatial R packages like {sf}. With Ubuntu 18.04, Ubuntu default versions of dependencies are sufficiently up-to-date, but you still need to install them.</p>
</blockquote>
<p>Whatever is the Ubuntu LTS distribution you are using, <strong>you’d better install UbuntuGIS PPA to be able to work with R packages for geographical data analyses</strong>. <em>By the way, you will also be able to install the latest version of QGIS with it.</em></p>
<p><em>In the terminal:</em></p>
<pre><code>sudo add-apt-repository 'deb http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu bionic main '
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 314DF160
sudo apt update
sudo apt install libgdal1-dev libproj-dev libgeos-dev libudunits2-dev libv8-dev libcairo2-dev libnetcdf-dev</code></pre>
<p>Then you can install your R packages using Ubuntu if you want them to always be up-to-date and correctly built for your distribution.</p>
<p><em>In the terminal (my personal selection):</em></p>
<pre><code>sudo apt install r-cran-gstat r-cran-maps r-cran-mapdata r-cran-ncdf4 r-cran-sp r-cran-sf r-cran-sp r-cran-raster r-cran-geor r-cran-ggmap r-cran-leaflet r-cran-rosm</code></pre>
<h2>Update R packages</h2>
<p><img src="https://i1.wp.com/rtask.thinkr.fr/wp-content/uploads/r-logo-e1533912828544.png?resize=150%2C116&ssl=1" alt="r-logo" width="150" class="wp-image-601" data-recalc-dims="1" height="116">You’re done ! You can now run R and do not forget to re-install all other R packages to be built with this new version of R. This requires <code>checkBuilt = TRUE</code> to force re-install packages even if you have the latest version available.</p>
<p><em>In R console:</em></p>
<pre><code>update.packages(ask = FALSE, checkBuilt = TRUE)</code></pre>
<p>If you need help for your R <a rel="nofollow" href="https://rtask.thinkr.fr/r-server-and-infrastructure-installation/" target="_blank">server installation and deployment of packages and shiny application</a>, you can <a rel="nofollow" href="https://rtask.thinkr.fr/contact/" target="_blank">contact the ThinkR team</a>.</p>
<p>The post <a rel="nofollow" href="https://rtask.thinkr.fr/blog/installation-of-r-3-5-on-ubuntu-18-04-lts-and-tips-for-spatial-packages/" target="_blank">Installation of R 3.5 on Ubuntu 18.04 LTS and tips for spatial packages</a> appeared first on <a rel="nofollow" href="https://rtask.thinkr.fr/" target="_blank">(en) The R Task Force</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rtask.thinkr.fr/blog/installation-of-r-3-5-on-ubuntu-18-04-lts-and-tips-for-spatial-packages/"> (en) The R Task Force</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/3-nnfQM3lW4" height="1"></a></div>